diff --git a/pom.xml b/pom.xml
index c914070c958..17a54382af0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -43,7 +43,7 @@
1.7
1.7
2.7.3
- 1.5.0
+ 1.6.1
4.11
2.11.8
2.11
@@ -98,6 +98,9 @@
smart-hadoop-support
+
+ true
+
diff --git a/smart-alluxio-support/smart-alluxio/pom.xml b/smart-alluxio-support/smart-alluxio/pom.xml
index c623bb24f83..68903a1c821 100644
--- a/smart-alluxio-support/smart-alluxio/pom.xml
+++ b/smart-alluxio-support/smart-alluxio/pom.xml
@@ -111,6 +111,11 @@
alluxio-core-client-fs
${alluxio.version}
+
+ org.alluxio
+ alluxio-core-server-common
+ ${alluxio.version}
+
org.alluxio
alluxio-minicluster
@@ -157,6 +162,17 @@
smart-metastore
1.4.0-SNAPSHOT
+
+ com.squareup
+ tape
+ 1.2.3
+
+
+ org.mockito
+ mockito-all
+ 1.10.8
+ test
+
@@ -179,4 +195,4 @@
-
+
\ No newline at end of file
diff --git a/smart-alluxio-support/smart-alluxio/src/main/java/alluxio/master/journal/ufs/AlluxioJournalUtil.java b/smart-alluxio-support/smart-alluxio/src/main/java/alluxio/master/journal/ufs/AlluxioJournalUtil.java
new file mode 100644
index 00000000000..af47dab6709
--- /dev/null
+++ b/smart-alluxio-support/smart-alluxio/src/main/java/alluxio/master/journal/ufs/AlluxioJournalUtil.java
@@ -0,0 +1,107 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package alluxio.master.journal.ufs;
+
+import alluxio.AlluxioURI;
+import alluxio.Configuration;
+import alluxio.Constants;
+import alluxio.PropertyKey;
+import alluxio.master.NoopMaster;
+import alluxio.master.journal.JournalReader;
+import alluxio.proto.journal.Journal;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.smartdata.conf.SmartConf;
+import org.smartdata.conf.SmartConfKeys;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+
+/**
+ * Util for reading the journal entries given a range of sequence numbers.
+ */
+public class AlluxioJournalUtil {
+
+ public static final Logger LOG = LoggerFactory.getLogger(AlluxioJournalUtil.class);
+
+ private static String sMaster = Constants.FILE_SYSTEM_MASTER_NAME;
+
+ /**
+ * @param conf smart configuration
+ * @return the current entry sequence number
+ */
+ public static Long getCurrentSeqNum(SmartConf conf) {
+ UfsJournal journal =
+ new UfsJournalSystem(getJournalLocation(conf), 0).createJournal(new NoopMaster(sMaster));
+ UfsJournalFile currentLog;
+ try {
+ currentLog = UfsJournalSnapshot.getCurrentLog(journal);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ long sn = -1L;
+ if (currentLog != null) {
+ try (JournalReader reader = new UfsJournalReader(journal, currentLog.getStart(), true)) {
+ Journal.JournalEntry entry;
+ while ((entry = reader.read()) != null) {
+ sn = entry.getSequenceNumber();
+ if (sn >= Long.MAX_VALUE) {
+ break;
+ }
+ }
+ } catch (Exception e) {
+ LOG.error("Failed to read next journal entry.", e);
+ }
+ }
+ return sn;
+ }
+
+ /**
+ * @param conf smart configuration
+ * @param startSn journal entry sequence number
+ * @return journal reader
+ */
+ public static JournalReader getJournalReaderFromSn(SmartConf conf, Long startSn) {
+ UfsJournal journal =
+ new UfsJournalSystem(getJournalLocation(conf), 0).createJournal(new NoopMaster(sMaster));
+ JournalReader reader = new UfsJournalReader(journal, startSn, true);
+ return reader;
+ }
+
+ /**
+ * @param conf smart configuration
+ * @return the journal location
+ */
+ private static URI getJournalLocation(SmartConf conf) {
+ String alluxioMasterJournalDir = conf.get(
+ SmartConfKeys.SMART_ALLUXIO_MASTER_JOURNAL_DIR_KEY, "/opt/alluxio/journal");
+ Configuration.set(PropertyKey.MASTER_JOURNAL_FOLDER, alluxioMasterJournalDir);
+ String journalDirectory = Configuration.get(PropertyKey.MASTER_JOURNAL_FOLDER);
+ if (!journalDirectory.endsWith(AlluxioURI.SEPARATOR)) {
+ journalDirectory += AlluxioURI.SEPARATOR;
+ }
+ try {
+ return new URI(journalDirectory);
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/smart-alluxio-support/smart-alluxio/src/main/java/org/smartdata/alluxio/AlluxioStatesUpdateService.java b/smart-alluxio-support/smart-alluxio/src/main/java/org/smartdata/alluxio/AlluxioStatesUpdateService.java
index 4a30c9e8fe5..ab88ed3707b 100644
--- a/smart-alluxio-support/smart-alluxio/src/main/java/org/smartdata/alluxio/AlluxioStatesUpdateService.java
+++ b/smart-alluxio-support/smart-alluxio/src/main/java/org/smartdata/alluxio/AlluxioStatesUpdateService.java
@@ -17,32 +17,42 @@
*/
package org.smartdata.alluxio;
+import alluxio.AlluxioURI;
+import alluxio.client.WriteType;
+import alluxio.client.file.FileOutStream;
+import alluxio.client.file.FileSystem;
+import alluxio.client.file.options.CreateFileOptions;
+import alluxio.client.file.options.DeleteOptions;
+import alluxio.exception.AlluxioException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smartdata.SmartContext;
-import org.smartdata.alluxio.metric.fetcher.AlluxioNamespaceFetcher;
+import org.smartdata.alluxio.metric.fetcher.AlluxioEntryFetcher;
import org.smartdata.metastore.MetaStore;
import org.smartdata.metastore.StatesUpdateService;
-import alluxio.client.file.FileSystem;
-
import java.io.IOException;
+import java.net.InetAddress;
+import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
/**
* Polls metrics and events from Alluxio Server
*/
public class AlluxioStatesUpdateService extends StatesUpdateService {
-
+ private static final String ALLUXIO_MOVER_ID_PATH = "/system/alluxio-mover.id";
+ private volatile boolean inSafeMode;
private FileSystem alluxioFs;
private ScheduledExecutorService executorService;
- private AlluxioNamespaceFetcher namespaceFetcher;
+ private AlluxioEntryFetcher alluxioEntryFetcher;
+ private FileOutStream moverIdOutStream;
public static final Logger LOG =
LoggerFactory.getLogger(AlluxioStatesUpdateService.class);
public AlluxioStatesUpdateService(SmartContext context, MetaStore metaStore) {
super(context, metaStore);
+ this.inSafeMode = true;
}
/**
@@ -55,29 +65,69 @@ public void init() throws IOException {
LOG.info("Initializing ...");
SmartContext context = getContext();
this.alluxioFs = AlluxioUtil.getAlluxioFs(context);
+ this.moverIdOutStream = checkAndMarkRunning(alluxioFs);
this.executorService = Executors.newScheduledThreadPool(4);
- this.namespaceFetcher = new AlluxioNamespaceFetcher(alluxioFs, metaStore,
- AlluxioNamespaceFetcher.DEFAULT_INTERVAL, executorService);
+ this.alluxioEntryFetcher = new AlluxioEntryFetcher(alluxioFs, metaStore,
+ executorService, new EntryFetchFinishedCallBack(), context.getConf());
LOG.info("Initialized.");
}
+ private class EntryFetchFinishedCallBack implements Callable