You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ct...@apache.org on 2014/11/25 23:36:48 UTC
[04/10] accumulo git commit: ACCUMULO-3199 Internal refactor to add
ClientContext
http://git-wip-us.apache.org/repos/asf/accumulo/blob/42c25faa/server/gc/src/main/java/org/apache/accumulo/gc/SimpleGarbageCollector.java
----------------------------------------------------------------------
diff --git a/server/gc/src/main/java/org/apache/accumulo/gc/SimpleGarbageCollector.java b/server/gc/src/main/java/org/apache/accumulo/gc/SimpleGarbageCollector.java
index f6ea8f7..1c1caa2 100644
--- a/server/gc/src/main/java/org/apache/accumulo/gc/SimpleGarbageCollector.java
+++ b/server/gc/src/main/java/org/apache/accumulo/gc/SimpleGarbageCollector.java
@@ -36,13 +36,11 @@ import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.apache.accumulo.core.client.BatchWriter;
import org.apache.accumulo.core.client.BatchWriterConfig;
import org.apache.accumulo.core.client.Connector;
-import org.apache.accumulo.core.client.Instance;
import org.apache.accumulo.core.client.IsolatedScanner;
import org.apache.accumulo.core.client.MutationsRejectedException;
import org.apache.accumulo.core.client.Scanner;
import org.apache.accumulo.core.client.TableNotFoundException;
import org.apache.accumulo.core.client.impl.Tables;
-import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.conf.Property;
import org.apache.accumulo.core.conf.SiteConfiguration;
import org.apache.accumulo.core.data.Key;
@@ -66,7 +64,6 @@ import org.apache.accumulo.core.replication.ReplicationTable;
import org.apache.accumulo.core.replication.ReplicationTableOfflineException;
import org.apache.accumulo.core.replication.proto.Replication.Status;
import org.apache.accumulo.core.security.Authorizations;
-import org.apache.accumulo.core.security.Credentials;
import org.apache.accumulo.core.security.SecurityUtil;
import org.apache.accumulo.core.security.thrift.TCredentials;
import org.apache.accumulo.core.trace.CountSampler;
@@ -78,7 +75,6 @@ import org.apache.accumulo.core.util.NamingThreadFactory;
import org.apache.accumulo.core.util.Pair;
import org.apache.accumulo.core.util.ServerServices;
import org.apache.accumulo.core.util.ServerServices.Service;
-import org.apache.accumulo.core.util.SslConnectionParams;
import org.apache.accumulo.core.util.UtilWaitThread;
import org.apache.accumulo.core.volume.Volume;
import org.apache.accumulo.core.zookeeper.ZooUtil;
@@ -86,6 +82,7 @@ import org.apache.accumulo.fate.zookeeper.ZooLock.LockLossReason;
import org.apache.accumulo.fate.zookeeper.ZooLock.LockWatcher;
import org.apache.accumulo.gc.replication.CloseWriteAheadLogReferences;
import org.apache.accumulo.server.Accumulo;
+import org.apache.accumulo.server.AccumuloServerContext;
import org.apache.accumulo.server.ServerConstants;
import org.apache.accumulo.server.ServerOpts;
import org.apache.accumulo.server.client.HdfsZooInstance;
@@ -94,7 +91,6 @@ import org.apache.accumulo.server.fs.VolumeManager;
import org.apache.accumulo.server.fs.VolumeManager.FileType;
import org.apache.accumulo.server.fs.VolumeManagerImpl;
import org.apache.accumulo.server.fs.VolumeUtil;
-import org.apache.accumulo.server.security.SystemCredentials;
import org.apache.accumulo.server.tables.TableManager;
import org.apache.accumulo.server.util.Halt;
import org.apache.accumulo.server.util.RpcWrapper;
@@ -114,7 +110,7 @@ import com.google.common.collect.Maps;
import com.google.common.net.HostAndPort;
import com.google.protobuf.InvalidProtocolBufferException;
-public class SimpleGarbageCollector implements Iface {
+public class SimpleGarbageCollector extends AccumuloServerContext implements Iface {
private static final Text EMPTY_TEXT = new Text();
/**
@@ -134,31 +130,24 @@ public class SimpleGarbageCollector implements Iface {
private static final Logger log = Logger.getLogger(SimpleGarbageCollector.class);
- private Credentials credentials;
private VolumeManager fs;
- private AccumuloConfiguration config;
private Opts opts = new Opts();
private ZooLock lock;
private GCStatus status = new GCStatus(new GcCycleStats(), new GcCycleStats(), new GcCycleStats(), new GcCycleStats());
- private Instance instance;
-
public static void main(String[] args) throws UnknownHostException, IOException {
SecurityUtil.serverLogin(SiteConfiguration.getInstance());
final String app = "gc";
Accumulo.setupLogging(app);
- Instance instance = HdfsZooInstance.getInstance();
- ServerConfigurationFactory conf = new ServerConfigurationFactory(instance);
+ ServerConfigurationFactory conf = new ServerConfigurationFactory(HdfsZooInstance.getInstance());
final VolumeManager fs = VolumeManagerImpl.get();
Accumulo.init(fs, conf, app);
Opts opts = new Opts();
opts.parseArgs(app, args);
- SimpleGarbageCollector gc = new SimpleGarbageCollector(opts);
- AccumuloConfiguration config = conf.getConfiguration();
+ SimpleGarbageCollector gc = new SimpleGarbageCollector(opts, fs, conf);
- gc.init(fs, instance, SystemCredentials.get(), config);
- DistributedTrace.enable(opts.getAddress(), app, config);
+ DistributedTrace.enable(opts.getAddress(), app, conf.getConfiguration());
try {
gc.run();
} finally {
@@ -172,17 +161,18 @@ public class SimpleGarbageCollector implements Iface {
* @param opts
* options
*/
- public SimpleGarbageCollector(Opts opts) {
+ public SimpleGarbageCollector(Opts opts, VolumeManager fs, ServerConfigurationFactory confFactory) {
+ super(confFactory);
this.opts = opts;
- }
+ this.fs = fs;
- /**
- * Gets the credentials used by this GC.
- *
- * @return credentials
- */
- Credentials getCredentials() {
- return credentials;
+ long gcDelay = getConfiguration().getTimeInMillis(Property.GC_CYCLE_DELAY);
+ log.info("start delay: " + getStartDelay() + " milliseconds");
+ log.info("time delay: " + gcDelay + " milliseconds");
+ log.info("safemode: " + opts.safeMode);
+ log.info("verbose: " + opts.verbose);
+ log.info("memory threshold: " + CANDIDATE_MEMORY_PERCENTAGE + " of " + Runtime.getRuntime().maxMemory() + " bytes");
+ log.info("delete threads: " + getNumDeleteThreads());
}
/**
@@ -191,7 +181,7 @@ public class SimpleGarbageCollector implements Iface {
* @return start delay, in milliseconds
*/
long getStartDelay() {
- return config.getTimeInMillis(Property.GC_CYCLE_START);
+ return getConfiguration().getTimeInMillis(Property.GC_CYCLE_START);
}
/**
@@ -209,7 +199,7 @@ public class SimpleGarbageCollector implements Iface {
* @return true if trash is used
*/
boolean isUsingTrash() {
- return !config.getBoolean(Property.GC_TRASH_IGNORE);
+ return !getConfiguration().getBoolean(Property.GC_TRASH_IGNORE);
}
/**
@@ -225,16 +215,7 @@ public class SimpleGarbageCollector implements Iface {
* @return number of delete threads
*/
int getNumDeleteThreads() {
- return config.getCount(Property.GC_DELETE_THREADS);
- }
-
- /**
- * Gets the instance used by this GC.
- *
- * @return instance
- */
- Instance getInstance() {
- return instance;
+ return getConfiguration().getCount(Property.GC_DELETE_THREADS);
}
/**
@@ -243,33 +224,7 @@ public class SimpleGarbageCollector implements Iface {
* @return True if files should be archived, false otherwise
*/
boolean shouldArchiveFiles() {
- return config.getBoolean(Property.GC_FILE_ARCHIVE);
- }
-
- /**
- * Initializes this garbage collector.
- *
- * @param fs
- * volume manager
- * @param instance
- * instance
- * @param credentials
- * credentials
- * @param config
- * system configuration
- */
- public void init(VolumeManager fs, Instance instance, Credentials credentials, AccumuloConfiguration config) {
- this.fs = fs;
- this.credentials = credentials;
- this.instance = instance;
- this.config = config;
- long gcDelay = config.getTimeInMillis(Property.GC_CYCLE_DELAY);
- log.info("start delay: " + getStartDelay() + " milliseconds");
- log.info("time delay: " + gcDelay + " milliseconds");
- log.info("safemode: " + opts.safeMode);
- log.info("verbose: " + opts.verbose);
- log.info("memory threshold: " + CANDIDATE_MEMORY_PERCENTAGE + " of " + Runtime.getRuntime().maxMemory() + " bytes");
- log.info("delete threads: " + getNumDeleteThreads());
+ return getConfiguration().getBoolean(Property.GC_FILE_ARCHIVE);
}
private class GCEnv implements GarbageCollectionEnvironment {
@@ -290,7 +245,7 @@ public class SimpleGarbageCollector implements Iface {
range = new Range(new Key(continueRow).followingKey(PartialKey.ROW), true, range.getEndKey(), range.isEndKeyInclusive());
}
- Scanner scanner = instance.getConnector(credentials.getPrincipal(), credentials.getToken()).createScanner(tableName, Authorizations.EMPTY);
+ Scanner scanner = getConnector().createScanner(tableName, Authorizations.EMPTY);
scanner.setRange(range);
List<String> result = new ArrayList<String>();
// find candidates for deletion; chop off the prefix
@@ -309,8 +264,7 @@ public class SimpleGarbageCollector implements Iface {
@Override
public Iterator<String> getBlipIterator() throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
- IsolatedScanner scanner = new IsolatedScanner(instance.getConnector(credentials.getPrincipal(), credentials.getToken()).createScanner(tableName,
- Authorizations.EMPTY));
+ IsolatedScanner scanner = new IsolatedScanner(getConnector().createScanner(tableName, Authorizations.EMPTY));
scanner.setRange(MetadataSchema.BlipSection.getRange());
@@ -324,8 +278,7 @@ public class SimpleGarbageCollector implements Iface {
@Override
public Iterator<Entry<Key,Value>> getReferenceIterator() throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
- IsolatedScanner scanner = new IsolatedScanner(instance.getConnector(credentials.getPrincipal(), credentials.getToken()).createScanner(tableName,
- Authorizations.EMPTY));
+ IsolatedScanner scanner = new IsolatedScanner(getConnector().createScanner(tableName, Authorizations.EMPTY));
scanner.fetchColumnFamily(DataFileColumnFamily.NAME);
scanner.fetchColumnFamily(ScanFileColumnFamily.NAME);
TabletsSection.ServerColumnFamily.DIRECTORY_COLUMN.fetch(scanner);
@@ -341,7 +294,7 @@ public class SimpleGarbageCollector implements Iface {
@Override
public Set<String> getTableIDs() {
- return Tables.getIdToNameMap(instance).keySet();
+ return Tables.getIdToNameMap(getInstance()).keySet();
}
@Override
@@ -358,7 +311,7 @@ public class SimpleGarbageCollector implements Iface {
return;
}
- Connector c = instance.getConnector(SystemCredentials.get().getPrincipal(), SystemCredentials.get().getToken());
+ Connector c = getConnector();
BatchWriter writer = c.createBatchWriter(tableName, new BatchWriterConfig());
// when deleting a dir and all files in that dir, only need to delete the dir
@@ -522,7 +475,7 @@ public class SimpleGarbageCollector implements Iface {
@Override
public Iterator<Entry<String,Status>> getReplicationNeededIterator() throws AccumuloException, AccumuloSecurityException {
- Connector conn = instance.getConnector(credentials.getPrincipal(), credentials.getToken());
+ Connector conn = getConnector();
try {
Scanner s = ReplicationTable.getScanner(conn);
StatusSection.limit(s);
@@ -607,7 +560,7 @@ public class SimpleGarbageCollector implements Iface {
// before running GarbageCollectWriteAheadLogs to ensure we delete as many files as possible.
Span replSpan = Trace.start("replicationClose");
try {
- CloseWriteAheadLogReferences closeWals = new CloseWriteAheadLogReferences(instance, credentials);
+ CloseWriteAheadLogReferences closeWals = new CloseWriteAheadLogReferences(this);
closeWals.run();
} catch (Exception e) {
log.error("Error trying to close write-ahead logs for replication table", e);
@@ -618,7 +571,7 @@ public class SimpleGarbageCollector implements Iface {
// Clean up any unused write-ahead logs
Span waLogs = Trace.start("walogs");
try {
- GarbageCollectWriteAheadLogs walogCollector = new GarbageCollectWriteAheadLogs(instance, fs, isUsingTrash());
+ GarbageCollectWriteAheadLogs walogCollector = new GarbageCollectWriteAheadLogs(this, fs, isUsingTrash());
log.info("Beginning garbage collection of write-ahead logs");
walogCollector.collect(status);
} catch (Exception e) {
@@ -630,7 +583,7 @@ public class SimpleGarbageCollector implements Iface {
// we just made a lot of metadata changes: flush them out
try {
- Connector connector = instance.getConnector(credentials.getPrincipal(), credentials.getToken());
+ Connector connector = getConnector();
connector.tableOperations().compact(MetadataTable.NAME, null, null, true, true);
connector.tableOperations().compact(RootTable.NAME, null, null, true, true);
} catch (Exception e) {
@@ -639,7 +592,7 @@ public class SimpleGarbageCollector implements Iface {
Trace.off();
try {
- long gcDelay = config.getTimeInMillis(Property.GC_CYCLE_DELAY);
+ long gcDelay = getConfiguration().getTimeInMillis(Property.GC_CYCLE_DELAY);
log.debug("Sleeping for " + gcDelay + " milliseconds");
Thread.sleep(gcDelay);
} catch (InterruptedException e) {
@@ -723,7 +676,7 @@ public class SimpleGarbageCollector implements Iface {
}
private void getZooLock(HostAndPort addr) throws KeeperException, InterruptedException {
- String path = ZooUtil.getRoot(instance) + Constants.ZGC_LOCK;
+ String path = ZooUtil.getRoot(getInstance()) + Constants.ZGC_LOCK;
LockWatcher lockWatcher = new LockWatcher() {
@Override
@@ -757,13 +710,13 @@ public class SimpleGarbageCollector implements Iface {
private HostAndPort startStatsService() throws UnknownHostException {
Processor<Iface> processor = new Processor<Iface>(RpcWrapper.service(this));
- int port = config.getPort(Property.GC_PORT);
- long maxMessageSize = config.getMemoryInBytes(Property.GENERAL_MAX_MESSAGE_SIZE);
+ int port = getConfiguration().getPort(Property.GC_PORT);
+ long maxMessageSize = getConfiguration().getMemoryInBytes(Property.GENERAL_MAX_MESSAGE_SIZE);
HostAndPort result = HostAndPort.fromParts(opts.getAddress(), port);
log.debug("Starting garbage collector listening on " + result);
try {
return TServerUtils.startTServer(result, processor, this.getClass().getSimpleName(), "GC Monitor Service", 2,
- config.getCount(Property.GENERAL_SIMPLETIMER_THREADPOOL_SIZE), 1000, maxMessageSize, SslConnectionParams.forServer(config), 0).address;
+ getConfiguration().getCount(Property.GENERAL_SIMPLETIMER_THREADPOOL_SIZE), 1000, maxMessageSize, getServerSslParams(), 0).address;
} catch (Exception ex) {
log.fatal(ex, ex);
throw new RuntimeException(ex);
http://git-wip-us.apache.org/repos/asf/accumulo/blob/42c25faa/server/gc/src/main/java/org/apache/accumulo/gc/replication/CloseWriteAheadLogReferences.java
----------------------------------------------------------------------
diff --git a/server/gc/src/main/java/org/apache/accumulo/gc/replication/CloseWriteAheadLogReferences.java b/server/gc/src/main/java/org/apache/accumulo/gc/replication/CloseWriteAheadLogReferences.java
index b0fd0f4..d99da6a 100644
--- a/server/gc/src/main/java/org/apache/accumulo/gc/replication/CloseWriteAheadLogReferences.java
+++ b/server/gc/src/main/java/org/apache/accumulo/gc/replication/CloseWriteAheadLogReferences.java
@@ -27,11 +27,8 @@ import org.apache.accumulo.core.client.BatchScanner;
import org.apache.accumulo.core.client.BatchWriter;
import org.apache.accumulo.core.client.BatchWriterConfig;
import org.apache.accumulo.core.client.Connector;
-import org.apache.accumulo.core.client.Instance;
import org.apache.accumulo.core.client.MutationsRejectedException;
import org.apache.accumulo.core.client.TableNotFoundException;
-import org.apache.accumulo.core.conf.AccumuloConfiguration;
-import org.apache.accumulo.core.conf.Property;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.Mutation;
import org.apache.accumulo.core.data.Range;
@@ -47,8 +44,6 @@ import org.apache.accumulo.core.replication.ReplicationTable;
import org.apache.accumulo.core.replication.StatusUtil;
import org.apache.accumulo.core.replication.proto.Replication.Status;
import org.apache.accumulo.core.security.Authorizations;
-import org.apache.accumulo.core.security.Credentials;
-import org.apache.accumulo.core.security.thrift.TCredentials;
import org.apache.accumulo.core.tabletserver.log.LogEntry;
import org.apache.accumulo.core.tabletserver.thrift.TabletClientService;
import org.apache.accumulo.core.trace.Span;
@@ -56,8 +51,7 @@ import org.apache.accumulo.core.trace.Trace;
import org.apache.accumulo.core.trace.Tracer;
import org.apache.accumulo.core.trace.thrift.TInfo;
import org.apache.accumulo.core.util.ThriftUtil;
-import org.apache.accumulo.server.conf.ServerConfigurationFactory;
-import org.apache.accumulo.server.security.SystemCredentials;
+import org.apache.accumulo.server.AccumuloServerContext;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.thrift.TException;
@@ -84,12 +78,10 @@ public class CloseWriteAheadLogReferences implements Runnable {
private static final String RFILE_SUFFIX = "." + RFile.EXTENSION;
- private Instance instance;
- private Credentials creds;
+ private final AccumuloServerContext context;
- public CloseWriteAheadLogReferences(Instance inst, Credentials creds) {
- this.instance = inst;
- this.creds = creds;
+ public CloseWriteAheadLogReferences(AccumuloServerContext context) {
+ this.context = context;
}
@Override
@@ -100,7 +92,7 @@ public class CloseWriteAheadLogReferences implements Runnable {
Connector conn;
try {
- conn = instance.getConnector(creds.getPrincipal(), creds.getToken());
+ conn = context.getConnector();
} catch (Exception e) {
log.error("Could not create connector", e);
throw new RuntimeException(e);
@@ -135,14 +127,12 @@ public class CloseWriteAheadLogReferences implements Runnable {
* If this code happened to run after the compaction but before the log is again referenced by a tabletserver, we might delete the WAL reference, only to
* have it recreated again which causes havoc with the replication status for a table.
*/
- final AccumuloConfiguration conf = new ServerConfigurationFactory(instance).getConfiguration();
final TInfo tinfo = Tracer.traceInfo();
- final TCredentials tcreds = SystemCredentials.get().toThrift(instance);
Set<String> activeWals;
Span findActiveWalsSpan = Trace.start("findActiveWals");
try {
sw.start();
- activeWals = getActiveWals(conf, tinfo, tcreds);
+ activeWals = getActiveWals(tinfo);
} finally {
sw.stop();
findActiveWalsSpan.stop();
@@ -307,7 +297,7 @@ public class CloseWriteAheadLogReferences implements Runnable {
private String getMasterAddress() {
try {
- List<String> locations = instance.getMasterLocations();
+ List<String> locations = context.getInstance().getMasterLocations();
if (locations.size() == 0)
return null;
return locations.get(0);
@@ -318,14 +308,14 @@ public class CloseWriteAheadLogReferences implements Runnable {
return null;
}
- private MasterClientService.Client getMasterConnection(AccumuloConfiguration conf) {
+ private MasterClientService.Client getMasterConnection() {
final String address = getMasterAddress();
try {
if (address == null) {
log.warn("Could not fetch Master address");
return null;
}
- return ThriftUtil.getClient(new MasterClientService.Client.Factory(), address, Property.GENERAL_RPC_TIMEOUT, conf);
+ return ThriftUtil.getClient(new MasterClientService.Client.Factory(), address, context);
} catch (Exception e) {
log.warn("Issue with masterConnection (" + address + ") " + e, e);
}
@@ -337,8 +327,8 @@ public class CloseWriteAheadLogReferences implements Runnable {
*
* @return Set of WALs in use by tservers, null if they cannot be computed for some reason
*/
- protected Set<String> getActiveWals(AccumuloConfiguration conf, TInfo tinfo, TCredentials tcreds) {
- List<String> tservers = getActiveTservers(conf, tinfo, tcreds);
+ protected Set<String> getActiveWals(TInfo tinfo) {
+ List<String> tservers = getActiveTservers(tinfo);
// Compute the total set of WALs used by tservers
Set<String> walogs = null;
@@ -349,7 +339,7 @@ public class CloseWriteAheadLogReferences implements Runnable {
// Alternatively, we might have to move to a solution that doesn't involve tserver RPC
for (String tserver : tservers) {
HostAndPort address = HostAndPort.fromString(tserver);
- List<String> activeWalsForServer = getActiveWalsForServer(conf, tinfo, tcreds, address);
+ List<String> activeWalsForServer = getActiveWalsForServer(tinfo, address);
if (null == activeWalsForServer) {
log.debug("Could not fetch active wals from " + address);
return null;
@@ -370,17 +360,17 @@ public class CloseWriteAheadLogReferences implements Runnable {
*
* @return The active tabletservers, null if they can't be computed.
*/
- protected List<String> getActiveTservers(AccumuloConfiguration conf, TInfo tinfo, TCredentials tcreds) {
+ protected List<String> getActiveTservers(TInfo tinfo) {
MasterClientService.Client client = null;
List<String> tservers = null;
try {
- client = getMasterConnection(conf);
+ client = getMasterConnection();
// Could do this through InstanceOperations, but that would set a bunch of new Watchers via ZK on every tserver
// node. The master is already tracking all of this info, so hopefully this is less overall work.
if (null != client) {
- tservers = client.getActiveTservers(tinfo, tcreds);
+ tservers = client.getActiveTservers(tinfo, context.rpcCreds());
}
} catch (TException e) {
// If we can't fetch the tabletservers, we can't fetch any active WALs
@@ -393,11 +383,11 @@ public class CloseWriteAheadLogReferences implements Runnable {
return tservers;
}
- protected List<String> getActiveWalsForServer(AccumuloConfiguration conf, TInfo tinfo, TCredentials tcreds, HostAndPort server) {
+ protected List<String> getActiveWalsForServer(TInfo tinfo, HostAndPort server) {
TabletClientService.Client tserverClient = null;
try {
- tserverClient = ThriftUtil.getClient(new TabletClientService.Client.Factory(), server, conf);
- return tserverClient.getActiveLogs(tinfo, tcreds);
+ tserverClient = ThriftUtil.getClient(new TabletClientService.Client.Factory(), server, context);
+ return tserverClient.getActiveLogs(tinfo, context.rpcCreds());
} catch (TTransportException e) {
log.warn("Failed to fetch active write-ahead logs from " + server, e);
return null;
http://git-wip-us.apache.org/repos/asf/accumulo/blob/42c25faa/server/gc/src/test/java/org/apache/accumulo/gc/GarbageCollectWriteAheadLogsTest.java
----------------------------------------------------------------------
diff --git a/server/gc/src/test/java/org/apache/accumulo/gc/GarbageCollectWriteAheadLogsTest.java b/server/gc/src/test/java/org/apache/accumulo/gc/GarbageCollectWriteAheadLogsTest.java
index 71e5f7d..f98721f 100644
--- a/server/gc/src/test/java/org/apache/accumulo/gc/GarbageCollectWriteAheadLogsTest.java
+++ b/server/gc/src/test/java/org/apache/accumulo/gc/GarbageCollectWriteAheadLogsTest.java
@@ -40,7 +40,7 @@ import org.apache.accumulo.core.client.BatchWriterConfig;
import org.apache.accumulo.core.client.Connector;
import org.apache.accumulo.core.client.Instance;
import org.apache.accumulo.core.client.mock.MockInstance;
-import org.apache.accumulo.core.client.security.tokens.PasswordToken;
+import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.Mutation;
import org.apache.accumulo.core.data.Value;
@@ -53,7 +53,8 @@ import org.apache.accumulo.core.replication.ReplicationSchema.StatusSection;
import org.apache.accumulo.core.replication.ReplicationTable;
import org.apache.accumulo.core.replication.StatusUtil;
import org.apache.accumulo.core.replication.proto.Replication.Status;
-import org.apache.accumulo.core.security.Credentials;
+import org.apache.accumulo.server.AccumuloServerContext;
+import org.apache.accumulo.server.conf.ServerConfigurationFactory;
import org.apache.accumulo.server.fs.VolumeManager;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.Path;
@@ -78,8 +79,10 @@ public class GarbageCollectWriteAheadLogsTest {
private static final String UUID3 = UUID.randomUUID().toString();
private Instance instance;
+ private AccumuloConfiguration systemConfig;
private VolumeManager volMgr;
private GarbageCollectWriteAheadLogs gcwal;
+ private AccumuloServerContext context;
private long modTime;
@Rule
@@ -88,8 +91,15 @@ public class GarbageCollectWriteAheadLogsTest {
@Before
public void setUp() throws Exception {
instance = createMock(Instance.class);
+ expect(instance.getInstanceID()).andReturn("mock").anyTimes();
+ systemConfig = createMock(AccumuloConfiguration.class);
volMgr = createMock(VolumeManager.class);
- gcwal = new GarbageCollectWriteAheadLogs(instance, volMgr, false);
+ ServerConfigurationFactory factory = createMock(ServerConfigurationFactory.class);
+ expect(factory.getConfiguration()).andReturn(systemConfig).anyTimes();
+ expect(factory.getInstance()).andReturn(instance).anyTimes();
+ replay(instance, factory);
+ AccumuloServerContext context = new AccumuloServerContext(factory);
+ gcwal = new GarbageCollectWriteAheadLogs(context, volMgr, false);
modTime = System.currentTimeMillis();
}
@@ -331,8 +341,8 @@ public class GarbageCollectWriteAheadLogsTest {
private List<Entry<Key,Value>> replData;
- ReplicationGCWAL(Instance instance, VolumeManager fs, boolean useTrash, List<Entry<Key,Value>> replData) throws IOException {
- super(instance, fs, useTrash);
+ ReplicationGCWAL(AccumuloServerContext context, VolumeManager fs, boolean useTrash, List<Entry<Key,Value>> replData) throws IOException {
+ super(context, fs, useTrash);
this.replData = replData;
}
@@ -351,7 +361,7 @@ public class GarbageCollectWriteAheadLogsTest {
LinkedList<Entry<Key,Value>> replData = new LinkedList<>();
replData.add(Maps.immutableEntry(new Key("/wals/" + file1, StatusSection.NAME.toString(), "1"), StatusUtil.fileCreatedValue(System.currentTimeMillis())));
- ReplicationGCWAL replGC = new ReplicationGCWAL(instance, volMgr, false, replData);
+ ReplicationGCWAL replGC = new ReplicationGCWAL(context, volMgr, false, replData);
replay(conn);
@@ -378,14 +388,13 @@ public class GarbageCollectWriteAheadLogsTest {
String file1 = UUID.randomUUID().toString(), file2 = UUID.randomUUID().toString();
Instance inst = new MockInstance(testName.getMethodName());
- Credentials creds = new Credentials("root", new PasswordToken(""));
- Connector conn = inst.getConnector(creds.getPrincipal(), creds.getToken());
+ AccumuloServerContext context = new AccumuloServerContext(new ServerConfigurationFactory(inst));
- GarbageCollectWriteAheadLogs gcWALs = new GarbageCollectWriteAheadLogs(inst, volMgr, false);
+ GarbageCollectWriteAheadLogs gcWALs = new GarbageCollectWriteAheadLogs(context, volMgr, false);
long file1CreateTime = System.currentTimeMillis();
long file2CreateTime = file1CreateTime + 50;
- BatchWriter bw = ReplicationTable.getBatchWriter(conn);
+ BatchWriter bw = ReplicationTable.getBatchWriter(context.getConnector());
Mutation m = new Mutation("/wals/" + file1);
StatusSection.add(m, new Text("1"), StatusUtil.fileCreatedValue(file1CreateTime));
bw.addMutation(m);
@@ -406,7 +415,7 @@ public class GarbageCollectWriteAheadLogsTest {
status.currentLog = cycleStats;
// We should iterate over two entries
- Assert.assertEquals(2, gcWALs.removeReplicationEntries(nameToFileMap, sortedWALogs, status, creds));
+ Assert.assertEquals(2, gcWALs.removeReplicationEntries(nameToFileMap, sortedWALogs, status));
// We should have noted that two files were still in use
Assert.assertEquals(2l, cycleStats.inUse);
@@ -420,10 +429,11 @@ public class GarbageCollectWriteAheadLogsTest {
String file1 = UUID.randomUUID().toString(), file2 = UUID.randomUUID().toString();
Instance inst = new MockInstance(testName.getMethodName());
- Credentials creds = new Credentials("root", new PasswordToken(""));
- Connector conn = inst.getConnector(creds.getPrincipal(), creds.getToken());
+ AccumuloServerContext context = new AccumuloServerContext(new ServerConfigurationFactory(inst));
- GarbageCollectWriteAheadLogs gcWALs = new GarbageCollectWriteAheadLogs(inst, volMgr, false);
+ Connector conn = context.getConnector();
+
+ GarbageCollectWriteAheadLogs gcWALs = new GarbageCollectWriteAheadLogs(context, volMgr, false);
long file1CreateTime = System.currentTimeMillis();
long file2CreateTime = file1CreateTime + 50;
@@ -450,7 +460,7 @@ public class GarbageCollectWriteAheadLogsTest {
status.currentLog = cycleStats;
// We should iterate over two entries
- Assert.assertEquals(2, gcWALs.removeReplicationEntries(nameToFileMap, sortedWALogs, status, creds));
+ Assert.assertEquals(2, gcWALs.removeReplicationEntries(nameToFileMap, sortedWALogs, status));
// We should have noted that two files were still in use
Assert.assertEquals(2l, cycleStats.inUse);
@@ -462,7 +472,8 @@ public class GarbageCollectWriteAheadLogsTest {
@Test
public void noReplicationTableDoesntLimitMetatdataResults() throws Exception {
Instance inst = new MockInstance(testName.getMethodName());
- Connector conn = inst.getConnector("root", new PasswordToken(""));
+ AccumuloServerContext context = new AccumuloServerContext(new ServerConfigurationFactory(inst));
+ Connector conn = context.getConnector();
String wal = "hdfs://localhost:8020/accumulo/wal/tserver+port/123456-1234-1234-12345678";
BatchWriter bw = conn.createBatchWriter(MetadataTable.NAME, new BatchWriterConfig());
@@ -471,7 +482,7 @@ public class GarbageCollectWriteAheadLogsTest {
bw.addMutation(m);
bw.close();
- GarbageCollectWriteAheadLogs gcWALs = new GarbageCollectWriteAheadLogs(inst, volMgr, false);
+ GarbageCollectWriteAheadLogs gcWALs = new GarbageCollectWriteAheadLogs(context, volMgr, false);
Iterable<Entry<Key,Value>> data = gcWALs.getReplicationStatusForFile(conn, wal);
Entry<Key,Value> entry = Iterables.getOnlyElement(data);
@@ -482,7 +493,9 @@ public class GarbageCollectWriteAheadLogsTest {
@Test
public void fetchesReplicationEntriesFromMetadataAndReplicationTables() throws Exception {
Instance inst = new MockInstance(testName.getMethodName());
- Connector conn = inst.getConnector("root", new PasswordToken(""));
+ AccumuloServerContext context = new AccumuloServerContext(new ServerConfigurationFactory(inst));
+ Connector conn = context.getConnector();
+
long walCreateTime = System.currentTimeMillis();
String wal = "hdfs://localhost:8020/accumulo/wal/tserver+port/123456-1234-1234-12345678";
BatchWriter bw = conn.createBatchWriter(MetadataTable.NAME, new BatchWriterConfig());
@@ -497,7 +510,7 @@ public class GarbageCollectWriteAheadLogsTest {
bw.addMutation(m);
bw.close();
- GarbageCollectWriteAheadLogs gcWALs = new GarbageCollectWriteAheadLogs(inst, volMgr, false);
+ GarbageCollectWriteAheadLogs gcWALs = new GarbageCollectWriteAheadLogs(context, volMgr, false);
Iterable<Entry<Key,Value>> iter = gcWALs.getReplicationStatusForFile(conn, wal);
Map<Key,Value> data = new HashMap<>();
http://git-wip-us.apache.org/repos/asf/accumulo/blob/42c25faa/server/gc/src/test/java/org/apache/accumulo/gc/SimpleGarbageCollectorTest.java
----------------------------------------------------------------------
diff --git a/server/gc/src/test/java/org/apache/accumulo/gc/SimpleGarbageCollectorTest.java b/server/gc/src/test/java/org/apache/accumulo/gc/SimpleGarbageCollectorTest.java
index 6195f42..99558b8 100644
--- a/server/gc/src/test/java/org/apache/accumulo/gc/SimpleGarbageCollectorTest.java
+++ b/server/gc/src/test/java/org/apache/accumulo/gc/SimpleGarbageCollectorTest.java
@@ -37,7 +37,9 @@ import org.apache.accumulo.core.security.Credentials;
import org.apache.accumulo.core.security.thrift.TCredentials;
import org.apache.accumulo.core.trace.thrift.TInfo;
import org.apache.accumulo.gc.SimpleGarbageCollector.Opts;
+import org.apache.accumulo.server.conf.ServerConfigurationFactory;
import org.apache.accumulo.server.fs.VolumeManager;
+import org.apache.accumulo.server.security.SystemCredentials;
import org.apache.hadoop.fs.Path;
import org.easymock.EasyMock;
import org.junit.Before;
@@ -55,11 +57,17 @@ public class SimpleGarbageCollectorTest {
public void setUp() {
volMgr = createMock(VolumeManager.class);
instance = createMock(Instance.class);
- credentials = createMock(Credentials.class);
+ expect(instance.getInstanceID()).andReturn("mock").anyTimes();
opts = new Opts();
- gc = new SimpleGarbageCollector(opts);
systemConfig = mockSystemConfig();
+ ServerConfigurationFactory factory = createMock(ServerConfigurationFactory.class);
+ expect(factory.getInstance()).andReturn(instance).anyTimes();
+ expect(factory.getConfiguration()).andReturn(mockSystemConfig()).anyTimes();
+ replay(instance, factory);
+
+ credentials = SystemCredentials.get(instance);
+ gc = new SimpleGarbageCollector(opts, volMgr, factory);
}
@Test
@@ -88,10 +96,9 @@ public class SimpleGarbageCollectorTest {
expect(systemConfig.getCount(Property.GC_DELETE_THREADS)).andReturn(2).times(2);
expect(systemConfig.getBoolean(Property.GC_TRASH_IGNORE)).andReturn(false);
replay(systemConfig);
- gc.init(volMgr, instance, credentials, systemConfig);
assertSame(volMgr, gc.getVolumeManager());
assertSame(instance, gc.getInstance());
- assertSame(credentials, gc.getCredentials());
+ assertEquals(credentials, gc.getCredentials());
assertTrue(gc.isUsingTrash());
assertEquals(1000L, gc.getStartDelay());
assertEquals(2, gc.getNumDeleteThreads());
@@ -99,7 +106,6 @@ public class SimpleGarbageCollectorTest {
@Test
public void testMoveToTrash_UsingTrash() throws Exception {
- gc.init(volMgr, instance, credentials, systemConfig);
Path path = createMock(Path.class);
expect(volMgr.moveToTrash(path)).andReturn(true);
replay(volMgr);
@@ -109,7 +115,6 @@ public class SimpleGarbageCollectorTest {
@Test
public void testMoveToTrash_UsingTrash_VolMgrFailure() throws Exception {
- gc.init(volMgr, instance, credentials, systemConfig);
Path path = createMock(Path.class);
expect(volMgr.moveToTrash(path)).andThrow(new FileNotFoundException());
replay(volMgr);
@@ -126,7 +131,6 @@ public class SimpleGarbageCollectorTest {
expect(systemConfig.getBoolean(Property.GC_FILE_ARCHIVE)).andReturn(false);
expect(systemConfig.getBoolean(Property.GC_TRASH_IGNORE)).andReturn(true);
replay(systemConfig);
- gc.init(volMgr, instance, credentials, systemConfig);
Path path = createMock(Path.class);
assertFalse(gc.archiveOrMoveToTrash(path));
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/42c25faa/server/gc/src/test/java/org/apache/accumulo/gc/replication/CloseWriteAheadLogReferencesTest.java
----------------------------------------------------------------------
diff --git a/server/gc/src/test/java/org/apache/accumulo/gc/replication/CloseWriteAheadLogReferencesTest.java b/server/gc/src/test/java/org/apache/accumulo/gc/replication/CloseWriteAheadLogReferencesTest.java
index 03a2678..cad1e01 100644
--- a/server/gc/src/test/java/org/apache/accumulo/gc/replication/CloseWriteAheadLogReferencesTest.java
+++ b/server/gc/src/test/java/org/apache/accumulo/gc/replication/CloseWriteAheadLogReferencesTest.java
@@ -55,10 +55,10 @@ import org.apache.accumulo.core.replication.ReplicationTable;
import org.apache.accumulo.core.replication.StatusUtil;
import org.apache.accumulo.core.replication.proto.Replication.Status;
import org.apache.accumulo.core.security.Authorizations;
-import org.apache.accumulo.core.security.Credentials;
-import org.apache.accumulo.core.security.thrift.TCredentials;
import org.apache.accumulo.core.tabletserver.log.LogEntry;
import org.apache.accumulo.core.trace.thrift.TInfo;
+import org.apache.accumulo.server.AccumuloServerContext;
+import org.apache.accumulo.server.conf.ServerConfigurationFactory;
import org.apache.hadoop.io.Text;
import org.easymock.EasyMock;
import org.easymock.IAnswer;
@@ -76,7 +76,6 @@ import com.google.common.net.HostAndPort;
public class CloseWriteAheadLogReferencesTest {
private CloseWriteAheadLogReferences refs;
- private Credentials creds;
private Instance inst;
@Rule
@@ -84,9 +83,14 @@ public class CloseWriteAheadLogReferencesTest {
@Before
public void setup() {
- creds = createMock(Credentials.class);
inst = createMock(Instance.class);
- refs = new CloseWriteAheadLogReferences(inst, creds);
+ expect(inst.getInstanceID()).andReturn(testName.getMethodName()).anyTimes();
+ AccumuloConfiguration systemConf = createMock(AccumuloConfiguration.class);
+ ServerConfigurationFactory factory = createMock(ServerConfigurationFactory.class);
+ expect(factory.getConfiguration()).andReturn(systemConf).anyTimes();
+ expect(factory.getInstance()).andReturn(inst).anyTimes();
+ replay(inst, factory);
+ refs = new CloseWriteAheadLogReferences(new AccumuloServerContext(factory));
}
@Test
@@ -376,21 +380,19 @@ public class CloseWriteAheadLogReferencesTest {
public void getActiveWals() throws Exception {
CloseWriteAheadLogReferences closeWals = EasyMock.createMockBuilder(CloseWriteAheadLogReferences.class).addMockedMethod("getActiveTservers")
.addMockedMethod("getActiveWalsForServer").createMock();
- AccumuloConfiguration conf = EasyMock.createMock(AccumuloConfiguration.class);
TInfo tinfo = EasyMock.createMock(TInfo.class);
- TCredentials tcreds = EasyMock.createMock(TCredentials.class);
List<String> tservers = Arrays.asList("localhost:12345", "localhost:12346");
- EasyMock.expect(closeWals.getActiveTservers(conf, tinfo, tcreds)).andReturn(tservers);
+ EasyMock.expect(closeWals.getActiveTservers(tinfo)).andReturn(tservers);
int numWals = 0;
for (String tserver : tservers) {
- EasyMock.expect(closeWals.getActiveWalsForServer(conf, tinfo, tcreds, HostAndPort.fromString(tserver))).andReturn(Arrays.asList("/wal" + numWals));
+ EasyMock.expect(closeWals.getActiveWalsForServer(tinfo, HostAndPort.fromString(tserver))).andReturn(Arrays.asList("/wal" + numWals));
numWals++;
}
EasyMock.replay(closeWals);
- Set<String> wals = closeWals.getActiveWals(conf, tinfo, tcreds);
+ Set<String> wals = closeWals.getActiveWals(tinfo);
EasyMock.verify(closeWals);
@@ -406,15 +408,13 @@ public class CloseWriteAheadLogReferencesTest {
public void offlineMaster() throws Exception {
CloseWriteAheadLogReferences closeWals = EasyMock.createMockBuilder(CloseWriteAheadLogReferences.class).addMockedMethod("getActiveTservers")
.addMockedMethod("getActiveWalsForServer").createMock();
- AccumuloConfiguration conf = EasyMock.createMock(AccumuloConfiguration.class);
TInfo tinfo = EasyMock.createMock(TInfo.class);
- TCredentials tcreds = EasyMock.createMock(TCredentials.class);
- EasyMock.expect(closeWals.getActiveTservers(conf, tinfo, tcreds)).andReturn(null);
+ EasyMock.expect(closeWals.getActiveTservers(tinfo)).andReturn(null);
EasyMock.replay(closeWals);
- Set<String> wals = closeWals.getActiveWals(conf, tinfo, tcreds);
+ Set<String> wals = closeWals.getActiveWals(tinfo);
EasyMock.verify(closeWals);
@@ -425,18 +425,16 @@ public class CloseWriteAheadLogReferencesTest {
public void offlineTserver() throws Exception {
CloseWriteAheadLogReferences closeWals = EasyMock.createMockBuilder(CloseWriteAheadLogReferences.class).addMockedMethod("getActiveTservers")
.addMockedMethod("getActiveWalsForServer").createMock();
- AccumuloConfiguration conf = EasyMock.createMock(AccumuloConfiguration.class);
TInfo tinfo = EasyMock.createMock(TInfo.class);
- TCredentials tcreds = EasyMock.createMock(TCredentials.class);
List<String> tservers = Arrays.asList("localhost:12345", "localhost:12346");
- EasyMock.expect(closeWals.getActiveTservers(conf, tinfo, tcreds)).andReturn(tservers);
- EasyMock.expect(closeWals.getActiveWalsForServer(conf, tinfo, tcreds, HostAndPort.fromString("localhost:12345"))).andReturn(Arrays.asList("/wal" + 0));
- EasyMock.expect(closeWals.getActiveWalsForServer(conf, tinfo, tcreds, HostAndPort.fromString("localhost:12346"))).andReturn(null);
+ EasyMock.expect(closeWals.getActiveTservers(tinfo)).andReturn(tservers);
+ EasyMock.expect(closeWals.getActiveWalsForServer(tinfo, HostAndPort.fromString("localhost:12345"))).andReturn(Arrays.asList("/wal" + 0));
+ EasyMock.expect(closeWals.getActiveWalsForServer(tinfo, HostAndPort.fromString("localhost:12346"))).andReturn(null);
EasyMock.replay(closeWals);
- Set<String> wals = closeWals.getActiveWals(conf, tinfo, tcreds);
+ Set<String> wals = closeWals.getActiveWals(tinfo);
EasyMock.verify(closeWals);
http://git-wip-us.apache.org/repos/asf/accumulo/blob/42c25faa/server/master/src/main/java/org/apache/accumulo/master/Master.java
----------------------------------------------------------------------
diff --git a/server/master/src/main/java/org/apache/accumulo/master/Master.java b/server/master/src/main/java/org/apache/accumulo/master/Master.java
index 93691fb..d5d5145 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/Master.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/Master.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -38,7 +39,6 @@ import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.apache.accumulo.core.client.Connector;
-import org.apache.accumulo.core.client.Instance;
import org.apache.accumulo.core.client.Scanner;
import org.apache.accumulo.core.client.TableNotFoundException;
import org.apache.accumulo.core.client.impl.Namespaces;
@@ -57,7 +57,9 @@ import org.apache.accumulo.core.master.state.tables.TableState;
import org.apache.accumulo.core.master.thrift.MasterClientService.Iface;
import org.apache.accumulo.core.master.thrift.MasterClientService.Processor;
import org.apache.accumulo.core.master.thrift.MasterGoalState;
+import org.apache.accumulo.core.master.thrift.MasterMonitorInfo;
import org.apache.accumulo.core.master.thrift.MasterState;
+import org.apache.accumulo.core.master.thrift.TableInfo;
import org.apache.accumulo.core.master.thrift.TabletServerStatus;
import org.apache.accumulo.core.metadata.MetadataTable;
import org.apache.accumulo.core.metadata.RootTable;
@@ -65,7 +67,6 @@ import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection;
import org.apache.accumulo.core.replication.ReplicationTable;
import org.apache.accumulo.core.replication.thrift.ReplicationCoordinator;
import org.apache.accumulo.core.security.Authorizations;
-import org.apache.accumulo.core.security.Credentials;
import org.apache.accumulo.core.security.NamespacePermission;
import org.apache.accumulo.core.security.SecurityUtil;
import org.apache.accumulo.core.security.TablePermission;
@@ -88,6 +89,7 @@ import org.apache.accumulo.master.replication.ReplicationDriver;
import org.apache.accumulo.master.replication.WorkDriver;
import org.apache.accumulo.master.state.TableCounts;
import org.apache.accumulo.server.Accumulo;
+import org.apache.accumulo.server.AccumuloServerContext;
import org.apache.accumulo.server.ServerConstants;
import org.apache.accumulo.server.ServerOpts;
import org.apache.accumulo.server.client.HdfsZooInstance;
@@ -109,13 +111,13 @@ import org.apache.accumulo.server.master.state.RootTabletStateStore;
import org.apache.accumulo.server.master.state.TServerInstance;
import org.apache.accumulo.server.master.state.TabletLocationState;
import org.apache.accumulo.server.master.state.TabletMigration;
+import org.apache.accumulo.server.master.state.TabletServerState;
import org.apache.accumulo.server.master.state.TabletState;
import org.apache.accumulo.server.master.state.ZooStore;
import org.apache.accumulo.server.master.state.ZooTabletStateStore;
import org.apache.accumulo.server.replication.ZooKeeperInitialization;
import org.apache.accumulo.server.security.AuditedSecurityOperation;
import org.apache.accumulo.server.security.SecurityOperation;
-import org.apache.accumulo.server.security.SystemCredentials;
import org.apache.accumulo.server.security.handler.ZKPermHandler;
import org.apache.accumulo.server.tables.TableManager;
import org.apache.accumulo.server.tables.TableObserver;
@@ -125,6 +127,7 @@ import org.apache.accumulo.server.util.MetadataTableUtil;
import org.apache.accumulo.server.util.RpcWrapper;
import org.apache.accumulo.server.util.TServerUtils;
import org.apache.accumulo.server.util.TServerUtils.ServerAddress;
+import org.apache.accumulo.server.util.TableInfoUtil;
import org.apache.accumulo.server.util.time.SimpleTimer;
import org.apache.accumulo.server.zookeeper.ZooLock;
import org.apache.accumulo.server.zookeeper.ZooReaderWriter;
@@ -150,7 +153,7 @@ import com.google.common.collect.Iterables;
*
* The master will also coordinate log recoveries and reports general status.
*/
-public class Master implements LiveTServerSet.Listener, TableObserver, CurrentState {
+public class Master extends AccumuloServerContext implements LiveTServerSet.Listener, TableObserver, CurrentState {
final static Logger log = Logger.getLogger(Master.class);
@@ -167,7 +170,6 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
final private static int MAX_BAD_STATUS_COUNT = 3;
final VolumeManager fs;
- final private Instance instance;
final private String hostname;
final private Object balancedNotifier = new Object();
final LiveTServerSet tserverSet;
@@ -246,7 +248,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
}
private void moveRootTabletToRootTable(IZooReaderWriter zoo) throws Exception {
- String dirZPath = ZooUtil.getRoot(instance) + RootTable.ZROOT_TABLET_PATH;
+ String dirZPath = ZooUtil.getRoot(getInstance()) + RootTable.ZROOT_TABLET_PATH;
if (!zoo.exists(dirZPath)) {
Path oldPath = fs.getFullPath(FileType.TABLE, "/" + MetadataTable.ID + "/root_tablet");
@@ -302,7 +304,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
log.info("Upgrading zookeeper");
IZooReaderWriter zoo = ZooReaderWriter.getInstance();
- final String zooRoot = ZooUtil.getRoot(instance);
+ final String zooRoot = ZooUtil.getRoot(getInstance());
log.debug("Handling updates for version " + accumuloPersistentVersion);
@@ -355,7 +357,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
}
// create initial namespaces
- String namespaces = ZooUtil.getRoot(instance) + Constants.ZNAMESPACES;
+ String namespaces = ZooUtil.getRoot(getInstance()) + Constants.ZNAMESPACES;
zoo.putPersistentData(namespaces, new byte[0], NodeExistsPolicy.SKIP);
for (Pair<String,String> namespace : Iterables.concat(
Collections.singleton(new Pair<String,String>(Namespaces.ACCUMULO_NAMESPACE, Namespaces.ACCUMULO_NAMESPACE_ID)),
@@ -363,26 +365,25 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
String ns = namespace.getFirst();
String id = namespace.getSecond();
log.debug("Upgrade creating namespace \"" + ns + "\" (ID: " + id + ")");
- if (!Namespaces.exists(instance, id))
- TableManager.prepareNewNamespaceState(instance.getInstanceID(), id, ns, NodeExistsPolicy.SKIP);
+ if (!Namespaces.exists(getInstance(), id))
+ TableManager.prepareNewNamespaceState(getInstance().getInstanceID(), id, ns, NodeExistsPolicy.SKIP);
}
// create replication table in zk
log.debug("Upgrade creating table " + ReplicationTable.NAME + " (ID: " + ReplicationTable.ID + ")");
- TableManager.prepareNewTableState(instance.getInstanceID(), ReplicationTable.ID, Namespaces.ACCUMULO_NAMESPACE_ID, ReplicationTable.NAME,
+ TableManager.prepareNewTableState(getInstance().getInstanceID(), ReplicationTable.ID, Namespaces.ACCUMULO_NAMESPACE_ID, ReplicationTable.NAME,
TableState.OFFLINE, NodeExistsPolicy.SKIP);
// create root table
log.debug("Upgrade creating table " + RootTable.NAME + " (ID: " + RootTable.ID + ")");
- TableManager.prepareNewTableState(instance.getInstanceID(), RootTable.ID, Namespaces.ACCUMULO_NAMESPACE_ID, RootTable.NAME, TableState.ONLINE,
+ TableManager.prepareNewTableState(getInstance().getInstanceID(), RootTable.ID, Namespaces.ACCUMULO_NAMESPACE_ID, RootTable.NAME, TableState.ONLINE,
NodeExistsPolicy.SKIP);
Initialize.initSystemTablesConfig();
// ensure root user can flush root table
- security.grantTablePermission(SystemCredentials.get().toThrift(instance), security.getRootUsername(), RootTable.ID, TablePermission.ALTER_TABLE,
- Namespaces.ACCUMULO_NAMESPACE_ID);
+ security.grantTablePermission(rpcCreds(), security.getRootUsername(), RootTable.ID, TablePermission.ALTER_TABLE, Namespaces.ACCUMULO_NAMESPACE_ID);
// put existing tables in the correct namespaces
- String tables = ZooUtil.getRoot(instance) + Constants.ZTABLES;
+ String tables = ZooUtil.getRoot(getInstance()) + Constants.ZTABLES;
for (String tableId : zoo.getChildren(tables)) {
String targetNamespace = (MetadataTable.ID.equals(tableId) || RootTable.ID.equals(tableId)) ? Namespaces.ACCUMULO_NAMESPACE_ID
: Namespaces.DEFAULT_NAMESPACE_ID;
@@ -400,8 +401,8 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
// add system namespace permissions to existing users
ZKPermHandler perm = new ZKPermHandler();
- perm.initialize(instance.getInstanceID(), true);
- String users = ZooUtil.getRoot(instance) + "/users";
+ perm.initialize(getInstance().getInstanceID(), true);
+ String users = ZooUtil.getRoot(getInstance()) + "/users";
for (String user : zoo.getChildren(users)) {
zoo.putPersistentData(users + "/" + user + "/Namespaces", new byte[0], NodeExistsPolicy.SKIP);
perm.grantNamespacePermission(user, Namespaces.ACCUMULO_NAMESPACE_ID, NamespacePermission.READ);
@@ -420,6 +421,8 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
private final ServerConfigurationFactory serverConfig;
+ private MasterClientServiceHandler clientHandler;
+
private void upgradeMetadata() {
// we make sure we're only doing the rest of this method once so that we can signal to other threads that an upgrade wasn't needed.
if (upgradeMetadataRunning.compareAndSet(false, true)) {
@@ -444,17 +447,17 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
log.info("Starting to upgrade metadata table.");
if (version == ServerConstants.MOVE_DELETE_MARKERS - 1) {
log.info("Updating Delete Markers in metadata table for version 1.4");
- MetadataTableUtil.moveMetaDeleteMarkersFrom14(instance, SystemCredentials.get());
+ MetadataTableUtil.moveMetaDeleteMarkersFrom14(Master.this);
version++;
}
if (version == ServerConstants.MOVE_TO_ROOT_TABLE - 1) {
log.info("Updating Delete Markers in metadata table.");
- MetadataTableUtil.moveMetaDeleteMarkers(instance, SystemCredentials.get());
+ MetadataTableUtil.moveMetaDeleteMarkers(Master.this);
version++;
}
if (version == ServerConstants.MOVE_TO_REPLICATION_TABLE - 1) {
log.info("Updating metadata table with entries for the replication table");
- MetadataTableUtil.createReplicationTable(instance, SystemCredentials.get());
+ MetadataTableUtil.createReplicationTable(Master.this);
version++;
}
log.info("Updating persistent data version.");
@@ -548,28 +551,23 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
}
public void mustBeOnline(final String tableId) throws ThriftTableOperationException {
- Tables.clearCache(instance);
- if (!Tables.getTableState(instance, tableId).equals(TableState.ONLINE))
+ Tables.clearCache(getInstance());
+ if (!Tables.getTableState(getInstance(), tableId).equals(TableState.ONLINE))
throw new ThriftTableOperationException(tableId, null, TableOperation.MERGE, TableOperationExceptionType.OFFLINE, "table is not online");
}
- public Connector getConnector() throws AccumuloException, AccumuloSecurityException {
- return instance.getConnector(SystemCredentials.get().getPrincipal(), SystemCredentials.get().getToken());
- }
-
private Master(ServerConfigurationFactory config, VolumeManager fs, String hostname) throws IOException {
+ super(config);
this.serverConfig = config;
- this.instance = config.getInstance();
this.fs = fs;
this.hostname = hostname;
AccumuloConfiguration aconf = serverConfig.getConfiguration();
log.info("Version " + Constants.VERSION);
- log.info("Instance " + instance.getInstanceID());
+ log.info("Instance " + getInstance().getInstanceID());
ThriftTransportPool.getInstance().setIdleTime(aconf.getTimeInMillis(Property.GENERAL_RPC_TIMEOUT));
- security = AuditedSecurityOperation.getInstance();
- tserverSet = new LiveTServerSet(instance, config.getConfiguration(), this);
+ tserverSet = new LiveTServerSet(this, this);
this.tabletBalancer = aconf.instantiateClassProperty(Property.MASTER_TABLET_BALANCER, TabletBalancer.class, new DefaultLoadBalancer());
this.tabletBalancer.init(serverConfig);
@@ -584,6 +582,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
throw new RuntimeException(e);
}
+ this.security = AuditedSecurityOperation.getInstance(this);
}
public TServerConnection getConnection(TServerInstance server) {
@@ -593,7 +592,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
public MergeInfo getMergeInfo(Text tableId) {
synchronized (mergeLock) {
try {
- String path = ZooUtil.getRoot(instance.getInstanceID()) + Constants.ZTABLES + "/" + tableId.toString() + "/merge";
+ String path = ZooUtil.getRoot(getInstance().getInstanceID()) + Constants.ZTABLES + "/" + tableId.toString() + "/merge";
if (!ZooReaderWriter.getInstance().exists(path))
return new MergeInfo();
byte[] data = ZooReaderWriter.getInstance().getData(path, new Stat());
@@ -614,7 +613,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
public void setMergeState(MergeInfo info, MergeState state) throws IOException, KeeperException, InterruptedException {
synchronized (mergeLock) {
- String path = ZooUtil.getRoot(instance.getInstanceID()) + Constants.ZTABLES + "/" + info.getExtent().getTableId().toString() + "/merge";
+ String path = ZooUtil.getRoot(getInstance().getInstanceID()) + Constants.ZTABLES + "/" + info.getExtent().getTableId().toString() + "/merge";
info.setState(state);
if (state.equals(MergeState.NONE)) {
ZooReaderWriter.getInstance().recursiveDelete(path, NodeMissingPolicy.SKIP);
@@ -635,7 +634,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
public void clearMergeState(Text tableId) throws IOException, KeeperException, InterruptedException {
synchronized (mergeLock) {
- String path = ZooUtil.getRoot(instance.getInstanceID()) + Constants.ZTABLES + "/" + tableId.toString() + "/merge";
+ String path = ZooUtil.getRoot(getInstance().getInstanceID()) + Constants.ZTABLES + "/" + tableId.toString() + "/merge";
ZooReaderWriter.getInstance().recursiveDelete(path, NodeMissingPolicy.SKIP);
mergeLock.notifyAll();
}
@@ -644,7 +643,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
void setMasterGoalState(MasterGoalState state) {
try {
- ZooReaderWriter.getInstance().putPersistentData(ZooUtil.getRoot(instance) + Constants.ZMASTER_GOAL_STATE, state.name().getBytes(),
+ ZooReaderWriter.getInstance().putPersistentData(ZooUtil.getRoot(getInstance()) + Constants.ZMASTER_GOAL_STATE, state.name().getBytes(),
NodeExistsPolicy.OVERWRITE);
} catch (Exception ex) {
log.error("Unable to set master goal state in zookeeper");
@@ -654,7 +653,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
MasterGoalState getMasterGoalState() {
while (true)
try {
- byte[] data = ZooReaderWriter.getInstance().getData(ZooUtil.getRoot(instance) + Constants.ZMASTER_GOAL_STATE, null);
+ byte[] data = ZooReaderWriter.getInstance().getData(ZooUtil.getRoot(getInstance()) + Constants.ZMASTER_GOAL_STATE, null);
return MasterGoalState.valueOf(new String(data));
} catch (Exception e) {
log.error("Problem getting real goal state: " + e);
@@ -815,7 +814,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
*/
private void cleanupOfflineMigrations() {
TableManager manager = TableManager.getInstance();
- for (String tableId : Tables.getIdToNameMap(instance).keySet()) {
+ for (String tableId : Tables.getIdToNameMap(getInstance()).keySet()) {
TableState state = manager.getTableState(tableId);
if (TableState.OFFLINE == state) {
clearMigrations(tableId);
@@ -1023,7 +1022,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
}
public void run() throws IOException, InterruptedException, KeeperException {
- final String zroot = ZooUtil.getRoot(instance);
+ final String zroot = ZooUtil.getRoot(getInstance());
getMasterLock(zroot + Constants.ZMASTER_LOCK);
@@ -1054,9 +1053,8 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
}
});
- Credentials systemCreds = SystemCredentials.get();
- watchers.add(new TabletGroupWatcher(this, new MetaDataStateStore(instance, systemCreds, this), null));
- watchers.add(new TabletGroupWatcher(this, new RootTabletStateStore(instance, systemCreds, this), watchers.get(0)));
+ watchers.add(new TabletGroupWatcher(this, new MetaDataStateStore(this, this), null));
+ watchers.add(new TabletGroupWatcher(this, new RootTabletStateStore(this, this), watchers.get(0)));
watchers.add(new TabletGroupWatcher(this, new ZooTabletStateStore(new ZooStore(zroot)), watchers.get(1)));
for (TabletGroupWatcher watcher : watchers) {
watcher.start();
@@ -1066,7 +1064,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
waitForMetadataUpgrade.await();
try {
- final AgeOffStore<Master> store = new AgeOffStore<Master>(new org.apache.accumulo.fate.ZooStore<Master>(ZooUtil.getRoot(instance) + Constants.ZFATE,
+ final AgeOffStore<Master> store = new AgeOffStore<Master>(new org.apache.accumulo.fate.ZooStore<Master>(ZooUtil.getRoot(getInstance()) + Constants.ZFATE,
ZooReaderWriter.getInstance()), 1000 * 60 * 60 * 8);
int threads = getConfiguration().getCount(Property.MASTER_FATE_THREADPOOL_SIZE);
@@ -1089,9 +1087,10 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
ZooKeeperInitialization.ensureZooKeeperInitialized(zReaderWriter, zroot);
- Processor<Iface> processor = new Processor<Iface>(RpcWrapper.service(new MasterClientServiceHandler(this)));
- ServerAddress sa = TServerUtils.startServer(getConfiguration(), hostname, Property.MASTER_CLIENTPORT, processor, "Master", "Master Client Service Handler",
- null, Property.MASTER_MINTHREADS, Property.MASTER_THREADCHECK, Property.GENERAL_MAX_MESSAGE_SIZE);
+ clientHandler = new MasterClientServiceHandler(this);
+ Processor<Iface> processor = new Processor<Iface>(RpcWrapper.service(clientHandler));
+ ServerAddress sa = TServerUtils.startServer(this, hostname, Property.MASTER_CLIENTPORT, processor, "Master", "Master Client Service Handler", null,
+ Property.MASTER_MINTHREADS, Property.MASTER_THREADCHECK, Property.GENERAL_MAX_MESSAGE_SIZE);
clientService = sa.server;
String address = sa.address.toString();
log.info("Setting master lock data to " + address);
@@ -1107,7 +1106,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
// Start the daemon to assign work to tservers to replicate to our peers
try {
- replicationWorkAssigner = new WorkDriver(this, getConnector());
+ replicationWorkAssigner = new WorkDriver(this);
} catch (AccumuloException | AccumuloSecurityException e) {
log.error("Caught exception trying to initialize replication WorkDriver", e);
throw new RuntimeException(e);
@@ -1117,19 +1116,18 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
// Start the replication coordinator which assigns tservers to service replication requests
ReplicationCoordinator.Processor<ReplicationCoordinator.Iface> replicationCoordinatorProcessor = new ReplicationCoordinator.Processor<ReplicationCoordinator.Iface>(
RpcWrapper.service(new MasterReplicationCoordinator(this)));
- ServerAddress replAddress = TServerUtils.startServer(getConfiguration(), hostname, Property.MASTER_REPLICATION_COORDINATOR_PORT,
- replicationCoordinatorProcessor, "Master Replication Coordinator", "Replication Coordinator", null, Property.MASTER_REPLICATION_COORDINATOR_MINTHREADS,
+ ServerAddress replAddress = TServerUtils.startServer(this, hostname, Property.MASTER_REPLICATION_COORDINATOR_PORT, replicationCoordinatorProcessor,
+ "Master Replication Coordinator", "Replication Coordinator", null, Property.MASTER_REPLICATION_COORDINATOR_MINTHREADS,
Property.MASTER_REPLICATION_COORDINATOR_THREADCHECK, Property.GENERAL_MAX_MESSAGE_SIZE);
log.info("Started replication coordinator service at " + replAddress.address);
// Advertise that port we used so peers don't have to be told what it is
- ZooReaderWriter.getInstance().putPersistentData(ZooUtil.getRoot(instance) + Constants.ZMASTER_REPLICATION_COORDINATOR_ADDR,
+ ZooReaderWriter.getInstance().putPersistentData(ZooUtil.getRoot(getInstance()) + Constants.ZMASTER_REPLICATION_COORDINATOR_ADDR,
replAddress.address.toString().getBytes(UTF_8), NodeExistsPolicy.OVERWRITE);
- final SystemCredentials creds = SystemCredentials.get();
try {
- ReplicationMetrics beanImpl = new ReplicationMetrics(this.instance.getConnector(creds.getPrincipal(), creds.getToken()));
+ ReplicationMetrics beanImpl = new ReplicationMetrics(this);
beanImpl.register();
} catch (Exception e) {
log.error("Error registering Replication metrics with JMX", e);
@@ -1255,8 +1253,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
opts.parseArgs(app, args);
String hostname = opts.getAddress();
Accumulo.setupLogging(app);
- Instance instance = HdfsZooInstance.getInstance();
- ServerConfigurationFactory conf = new ServerConfigurationFactory(instance);
+ ServerConfigurationFactory conf = new ServerConfigurationFactory(HdfsZooInstance.getInstance());
VolumeManager fs = VolumeManagerImpl.get();
Accumulo.init(fs, conf, app);
Master master = new Master(conf, fs, hostname);
@@ -1272,7 +1269,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
@Override
public void update(LiveTServerSet current, Set<TServerInstance> deleted, Set<TServerInstance> added) {
- DeadServerList obit = new DeadServerList(ZooUtil.getRoot(instance) + Constants.ZDEADTSERVERS);
+ DeadServerList obit = new DeadServerList(ZooUtil.getRoot(getInstance()) + Constants.ZDEADTSERVERS);
if (added.size() > 0) {
log.info("New servers: " + added);
for (TServerInstance up : added)
@@ -1361,7 +1358,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
}
TableManager manager = TableManager.getInstance();
- for (String tableId : Tables.getIdToNameMap(instance).keySet()) {
+ for (String tableId : Tables.getIdToNameMap(getInstance()).keySet()) {
TableState state = manager.getTableState(tableId);
if (state != null) {
if (state == TableState.ONLINE)
@@ -1379,7 +1376,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
@Override
public Collection<MergeInfo> merges() {
List<MergeInfo> result = new ArrayList<MergeInfo>();
- for (String tableId : Tables.getIdToNameMap(instance).keySet()) {
+ for (String tableId : Tables.getIdToNameMap(getInstance()).keySet()) {
result.add(getMergeInfo(new Text(tableId)));
}
return result;
@@ -1395,14 +1392,6 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
return nextEvent;
}
- public Instance getInstance() {
- return this.instance;
- }
-
- public AccumuloConfiguration getConfiguration() {
- return serverConfig.getConfiguration();
- }
-
public ServerConfigurationFactory getConfigurationFactory() {
return serverConfig;
}
@@ -1438,4 +1427,35 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
} while (displayUnassigned() > 0 || migrations.size() > 0 || eventCounter != nextEvent.waitForEvents(0, 0));
}
}
+
+ public MasterMonitorInfo getMasterMonitorInfo() {
+ final MasterMonitorInfo result = new MasterMonitorInfo();
+
+ result.tServerInfo = new ArrayList<TabletServerStatus>();
+ result.tableMap = new DefaultMap<String,TableInfo>(new TableInfo());
+ for (Entry<TServerInstance,TabletServerStatus> serverEntry : tserverStatus.entrySet()) {
+ final TabletServerStatus status = serverEntry.getValue();
+ result.tServerInfo.add(status);
+ for (Entry<String,TableInfo> entry : status.tableMap.entrySet()) {
+ TableInfoUtil.add(result.tableMap.get(entry.getKey()), entry.getValue());
+ }
+ }
+ result.badTServers = new HashMap<String,Byte>();
+ synchronized (badServers) {
+ for (TServerInstance bad : badServers.keySet()) {
+ result.badTServers.put(bad.hostPort(), TabletServerState.UNRESPONSIVE.getId());
+ }
+ }
+ result.state = getMasterState();
+ result.goalState = getMasterGoalState();
+ result.unassignedTablets = displayUnassigned();
+ result.serversShuttingDown = new HashSet<String>();
+ synchronized (serversToShutdown) {
+ for (TServerInstance server : serversToShutdown)
+ result.serversShuttingDown.add(server.hostPort());
+ }
+ DeadServerList obit = new DeadServerList(ZooUtil.getRoot(getInstance()) + Constants.ZDEADTSERVERS);
+ result.deadTabletServers = obit.getList();
+ return result;
+ }
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/42c25faa/server/master/src/main/java/org/apache/accumulo/master/MasterClientServiceHandler.java
----------------------------------------------------------------------
diff --git a/server/master/src/main/java/org/apache/accumulo/master/MasterClientServiceHandler.java b/server/master/src/main/java/org/apache/accumulo/master/MasterClientServiceHandler.java
index 9a3e532..72cba26 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/MasterClientServiceHandler.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/MasterClientServiceHandler.java
@@ -18,7 +18,6 @@ package org.apache.accumulo.master;
import java.nio.ByteBuffer;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -49,9 +48,7 @@ import org.apache.accumulo.core.master.thrift.MasterClientService;
import org.apache.accumulo.core.master.thrift.MasterGoalState;
import org.apache.accumulo.core.master.thrift.MasterMonitorInfo;
import org.apache.accumulo.core.master.thrift.MasterState;
-import org.apache.accumulo.core.master.thrift.TableInfo;
import org.apache.accumulo.core.master.thrift.TabletLoadState;
-import org.apache.accumulo.core.master.thrift.TabletServerStatus;
import org.apache.accumulo.core.master.thrift.TabletSplit;
import org.apache.accumulo.core.metadata.MetadataTable;
import org.apache.accumulo.core.metadata.RootTable;
@@ -63,23 +60,17 @@ import org.apache.accumulo.core.security.thrift.TCredentials;
import org.apache.accumulo.core.trace.thrift.TInfo;
import org.apache.accumulo.core.util.ByteBufferUtil;
import org.apache.accumulo.core.util.UtilWaitThread;
-import org.apache.accumulo.core.zookeeper.ZooUtil;
import org.apache.accumulo.fate.zookeeper.IZooReaderWriter;
import org.apache.accumulo.fate.zookeeper.IZooReaderWriter.Mutator;
import org.apache.accumulo.master.tableOps.TraceRepo;
import org.apache.accumulo.master.tserverOps.ShutdownTServer;
import org.apache.accumulo.server.client.ClientServiceHandler;
-import org.apache.accumulo.server.conf.ServerConfigurationFactory;
import org.apache.accumulo.server.master.LiveTServerSet.TServerConnection;
import org.apache.accumulo.server.master.balancer.DefaultLoadBalancer;
import org.apache.accumulo.server.master.balancer.TabletBalancer;
-import org.apache.accumulo.server.master.state.DeadServerList;
import org.apache.accumulo.server.master.state.TServerInstance;
-import org.apache.accumulo.server.master.state.TabletServerState;
-import org.apache.accumulo.server.util.DefaultMap;
import org.apache.accumulo.server.util.NamespacePropUtil;
import org.apache.accumulo.server.util.SystemPropUtil;
-import org.apache.accumulo.server.util.TableInfoUtil;
import org.apache.accumulo.server.util.TablePropUtil;
import org.apache.accumulo.server.util.TabletIterator.TabletDeletedException;
import org.apache.accumulo.server.zookeeper.ZooReaderWriter;
@@ -104,8 +95,7 @@ class MasterClientServiceHandler extends FateServiceHandler implements MasterCli
String namespaceId = Tables.getNamespaceId(instance, tableId);
master.security.canFlush(c, tableId, namespaceId);
- String zTablePath = Constants.ZROOT + "/" + master.getInstance().getInstanceID() + Constants.ZTABLES + "/" + tableId
- + Constants.ZTABLE_FLUSH_ID;
+ String zTablePath = Constants.ZROOT + "/" + master.getInstance().getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_FLUSH_ID;
IZooReaderWriter zoo = ZooReaderWriter.getInstance();
byte fid[];
@@ -245,34 +235,7 @@ class MasterClientServiceHandler extends FateServiceHandler implements MasterCli
@Override
public MasterMonitorInfo getMasterStats(TInfo info, TCredentials credentials) throws ThriftSecurityException {
- final MasterMonitorInfo result = new MasterMonitorInfo();
-
- result.tServerInfo = new ArrayList<TabletServerStatus>();
- result.tableMap = new DefaultMap<String,TableInfo>(new TableInfo());
- for (Entry<TServerInstance,TabletServerStatus> serverEntry : master.tserverStatus.entrySet()) {
- final TabletServerStatus status = serverEntry.getValue();
- result.tServerInfo.add(status);
- for (Entry<String,TableInfo> entry : status.tableMap.entrySet()) {
- TableInfoUtil.add(result.tableMap.get(entry.getKey()), entry.getValue());
- }
- }
- result.badTServers = new HashMap<String,Byte>();
- synchronized (master.badServers) {
- for (TServerInstance bad : master.badServers.keySet()) {
- result.badTServers.put(bad.hostPort(), TabletServerState.UNRESPONSIVE.getId());
- }
- }
- result.state = master.getMasterState();
- result.goalState = master.getMasterGoalState();
- result.unassignedTablets = master.displayUnassigned();
- result.serversShuttingDown = new HashSet<String>();
- synchronized (master.serversToShutdown) {
- for (TServerInstance server : master.serversToShutdown)
- result.serversShuttingDown.add(server.hostPort());
- }
- DeadServerList obit = new DeadServerList(ZooUtil.getRoot(master.getInstance()) + Constants.ZDEADTSERVERS);
- result.deadTabletServers = obit.getList();
- return result;
+ return master.getMasterMonitorInfo();
}
@Override
@@ -459,9 +422,8 @@ class MasterClientServiceHandler extends FateServiceHandler implements MasterCli
private void updatePlugins(String property) {
if (property.equals(Property.MASTER_TABLET_BALANCER.getKey())) {
- ServerConfigurationFactory factory = new ServerConfigurationFactory(master.getInstance());
- TabletBalancer balancer = factory.getConfiguration().instantiateClassProperty(Property.MASTER_TABLET_BALANCER,
- TabletBalancer.class, new DefaultLoadBalancer());
+ TabletBalancer balancer = master.getConfiguration().instantiateClassProperty(Property.MASTER_TABLET_BALANCER, TabletBalancer.class,
+ new DefaultLoadBalancer());
balancer.init(master.getConfigurationFactory());
master.tabletBalancer = balancer;
log.info("tablet balancer changed to " + master.tabletBalancer.getClass().getName());
http://git-wip-us.apache.org/repos/asf/accumulo/blob/42c25faa/server/master/src/main/java/org/apache/accumulo/master/TabletGroupWatcher.java
----------------------------------------------------------------------
diff --git a/server/master/src/main/java/org/apache/accumulo/master/TabletGroupWatcher.java b/server/master/src/main/java/org/apache/accumulo/master/TabletGroupWatcher.java
index f5ed941..3d39891 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/TabletGroupWatcher.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/TabletGroupWatcher.java
@@ -76,7 +76,6 @@ import org.apache.accumulo.server.master.state.TabletLocationState;
import org.apache.accumulo.server.master.state.TabletLocationState.BadLocationStateException;
import org.apache.accumulo.server.master.state.TabletState;
import org.apache.accumulo.server.master.state.TabletStateStore;
-import org.apache.accumulo.server.security.SystemCredentials;
import org.apache.accumulo.server.tables.TableManager;
import org.apache.accumulo.server.tablets.TabletTime;
import org.apache.accumulo.server.util.MetadataTableUtil;
@@ -505,7 +504,7 @@ class TabletGroupWatcher extends Daemon {
if (key.compareColumnFamily(DataFileColumnFamily.NAME) == 0) {
datafiles.add(new FileRef(this.master.fs, key));
if (datafiles.size() > 1000) {
- MetadataTableUtil.addDeleteEntries(extent, datafiles, SystemCredentials.get());
+ MetadataTableUtil.addDeleteEntries(extent, datafiles, master);
datafiles.clear();
}
} else if (TabletsSection.ServerColumnFamily.TIME_COLUMN.hasColumns(key)) {
@@ -522,12 +521,12 @@ class TabletGroupWatcher extends Daemon {
datafiles.add(new FileRef(path, this.master.fs.getFullPath(FileType.TABLE, Path.SEPARATOR + extent.getTableId() + path)));
}
if (datafiles.size() > 1000) {
- MetadataTableUtil.addDeleteEntries(extent, datafiles, SystemCredentials.get());
+ MetadataTableUtil.addDeleteEntries(extent, datafiles, master);
datafiles.clear();
}
}
}
- MetadataTableUtil.addDeleteEntries(extent, datafiles, SystemCredentials.get());
+ MetadataTableUtil.addDeleteEntries(extent, datafiles, master);
BatchWriter bw = conn.createBatchWriter(targetSystemTable, new BatchWriterConfig());
try {
deleteTablets(info, deleteRange, bw, conn);
@@ -552,7 +551,7 @@ class TabletGroupWatcher extends Daemon {
Master.log.debug("Recreating the last tablet to point to " + extent.getPrevEndRow());
String tdir = master.getFileSystem().choose(ServerConstants.getBaseUris()) + Constants.HDFS_TABLES_DIR + Path.SEPARATOR + extent.getTableId()
+ Constants.DEFAULT_TABLET_LOCATION;
- MetadataTableUtil.addTablet(new KeyExtent(extent.getTableId(), null, extent.getPrevEndRow()), tdir, SystemCredentials.get(), timeType, this.master.masterLock);
+ MetadataTableUtil.addTablet(new KeyExtent(extent.getTableId(), null, extent.getPrevEndRow()), tdir, master, timeType, this.master.masterLock);
}
} catch (Exception ex) {
throw new AccumuloException(ex);
http://git-wip-us.apache.org/repos/asf/accumulo/blob/42c25faa/server/master/src/main/java/org/apache/accumulo/master/metrics/ReplicationMetrics.java
----------------------------------------------------------------------
diff --git a/server/master/src/main/java/org/apache/accumulo/master/metrics/ReplicationMetrics.java b/server/master/src/main/java/org/apache/accumulo/master/metrics/ReplicationMetrics.java
index 762b18d..39112d0 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/metrics/ReplicationMetrics.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/metrics/ReplicationMetrics.java
@@ -24,54 +24,40 @@ import javax.management.ObjectName;
import org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.AccumuloSecurityException;
-import org.apache.accumulo.core.client.Connector;
-import org.apache.accumulo.core.client.impl.MasterClient;
-import org.apache.accumulo.core.master.thrift.MasterClientService;
-import org.apache.accumulo.core.master.thrift.MasterMonitorInfo;
+import org.apache.accumulo.core.client.impl.Tables;
+import org.apache.accumulo.core.master.state.tables.TableState;
import org.apache.accumulo.core.replication.ReplicationTable;
import org.apache.accumulo.core.replication.ReplicationTarget;
-import org.apache.accumulo.core.trace.Tracer;
-import org.apache.accumulo.server.client.HdfsZooInstance;
+import org.apache.accumulo.master.Master;
import org.apache.accumulo.server.metrics.AbstractMetricsImpl;
import org.apache.accumulo.server.replication.ReplicationUtil;
-import org.apache.accumulo.server.security.SystemCredentials;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* JMX bindings to expose 'high-level' metrics about Replication
*/
public class ReplicationMetrics extends AbstractMetricsImpl implements ReplicationMetricsMBean {
- private static final Logger log = LoggerFactory.getLogger(ReplicationMetrics.class);
private static final String METRICS_PREFIX = "replication";
- private Connector conn;
+ private Master master;
private ObjectName objectName = null;
private ReplicationUtil replicationUtil;
- public ReplicationMetrics(Connector conn) throws MalformedObjectNameException {
+ public ReplicationMetrics(Master master) throws MalformedObjectNameException, AccumuloException, AccumuloSecurityException {
super();
- this.conn = conn;
+ this.master = master;
objectName = new ObjectName("accumulo.server.metrics:service=Replication Metrics,name=ReplicationMBean,instance=" + Thread.currentThread().getName());
- replicationUtil = new ReplicationUtil();
+ replicationUtil = new ReplicationUtil(master);
}
@Override
public int getNumFilesPendingReplication() {
- if (!ReplicationTable.isOnline(conn)) {
- return 0;
- }
- Map<String,String> properties;
- try {
- properties = conn.instanceOperations().getSystemConfiguration();
- } catch (AccumuloException | AccumuloSecurityException e) {
- log.debug("Could not extract system configuration", e);
+ if (TableState.ONLINE != Tables.getTableState(master.getInstance(), ReplicationTable.ID)) {
return 0;
}
// Get all of the configured replication peers
- Map<String,String> peers = replicationUtil.getPeers(properties);
+ Map<String,String> peers = replicationUtil.getPeers();
// A quick lookup to see if have any replication peer configured
if (peers.isEmpty()) {
@@ -79,10 +65,10 @@ public class ReplicationMetrics extends AbstractMetricsImpl implements Replicati
}
// The total set of configured targets
- Set<ReplicationTarget> allConfiguredTargets = replicationUtil.getReplicationTargets(conn.tableOperations());
+ Set<ReplicationTarget> allConfiguredTargets = replicationUtil.getReplicationTargets();
// Number of files per target we have to replicate
- Map<ReplicationTarget,Long> targetCounts = replicationUtil.getPendingReplications(conn);
+ Map<ReplicationTarget,Long> targetCounts = replicationUtil.getPendingReplications();
int filesPending = 0;
@@ -100,50 +86,12 @@ public class ReplicationMetrics extends AbstractMetricsImpl implements Replicati
@Override
public int getNumConfiguredPeers() {
- Map<String,String> properties;
- try {
- properties = conn.instanceOperations().getSystemConfiguration();
- } catch (AccumuloException | AccumuloSecurityException e) {
- log.debug("Could not extract system configuration", e);
- return 0;
- }
-
- // Get all of the configured replication peers
- return replicationUtil.getPeers(properties).size();
+ return replicationUtil.getPeers().size();
}
@Override
public int getMaxReplicationThreads() {
- MasterMonitorInfo mmi = null;
- for (int i = 0; i < 10; i++) {
- MasterClientService.Iface client = null;
- try {
- client = MasterClient.getConnection(HdfsZooInstance.getInstance());
- if (client != null) {
- mmi = client.getMasterStats(Tracer.traceInfo(), SystemCredentials.get().toThrift(HdfsZooInstance.getInstance()));
- break;
- }
- } catch (Exception e) {
- log.debug("Error fetching stats: " + e);
- } finally {
- if (client != null) {
- MasterClient.close(client);
- }
- }
- }
-
- if (null != mmi) {
- try {
- return replicationUtil.getMaxReplicationThreads(conn, mmi);
- } catch (AccumuloException e) {
- log.warn("Failed to fetch replication work queue size", e);
- } catch (AccumuloSecurityException e) {
- log.warn("Failed to fetch replication work queue size", e);
- }
- }
-
- log.warn("Could not fetch metrics information from Master");
- return -1;
+ return replicationUtil.getMaxReplicationThreads(master.getMasterMonitorInfo());
}
@Override
http://git-wip-us.apache.org/repos/asf/accumulo/blob/42c25faa/server/master/src/main/java/org/apache/accumulo/master/replication/MasterReplicationCoordinator.java
----------------------------------------------------------------------
diff --git a/server/master/src/main/java/org/apache/accumulo/master/replication/MasterReplicationCoordinator.java b/server/master/src/main/java/org/apache/accumulo/master/replication/MasterReplicationCoordinator.java
index 8218c8a..73131c7 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/replication/MasterReplicationCoordinator.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/replication/MasterReplicationCoordinator.java
@@ -34,7 +34,6 @@ import org.apache.accumulo.fate.zookeeper.ZooReader;
import org.apache.accumulo.master.Master;
import org.apache.accumulo.server.master.state.TServerInstance;
import org.apache.accumulo.server.security.SecurityOperation;
-import org.apache.accumulo.server.security.SystemCredentials;
import org.apache.thrift.TException;
import org.apache.zookeeper.KeeperException;
import org.slf4j.Logger;
@@ -63,14 +62,14 @@ public class MasterReplicationCoordinator implements ReplicationCoordinator.Ifac
this.rand = new Random(358923462l);
this.inst = master.getInstance();
this.reader = reader;
- this.security = SecurityOperation.getInstance(inst.getInstanceID(), false);
+ this.security = SecurityOperation.getInstance(master, false);
}
@Override
public String getServicerAddress(String remoteTableId, TCredentials creds) throws ReplicationCoordinatorException, TException {
try {
- security.authenticateUser(SystemCredentials.get().toThrift(inst), creds);
+ security.authenticateUser(master.rpcCreds(), creds);
} catch (ThriftSecurityException e) {
log.error("{} failed to authenticate for replication to {}", creds.getPrincipal(), remoteTableId);
throw new ReplicationCoordinatorException(ReplicationCoordinatorErrorCode.CANNOT_AUTHENTICATE, "Could not authenticate " + creds.getPrincipal());
http://git-wip-us.apache.org/repos/asf/accumulo/blob/42c25faa/server/master/src/main/java/org/apache/accumulo/master/replication/ReplicationDriver.java
----------------------------------------------------------------------
diff --git a/server/master/src/main/java/org/apache/accumulo/master/replication/ReplicationDriver.java b/server/master/src/main/java/org/apache/accumulo/master/replication/ReplicationDriver.java
index f822a90..63c6b20 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/replication/ReplicationDriver.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/replication/ReplicationDriver.java
@@ -73,7 +73,7 @@ public class ReplicationDriver extends Daemon {
}
statusMaker = new StatusMaker(conn);
- workMaker = new WorkMaker(conn);
+ workMaker = new WorkMaker(master, conn);
finishedWorkUpdater = new FinishedWorkUpdater(conn);
rcrr = new RemoveCompleteReplicationRecords(conn);
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/42c25faa/server/master/src/main/java/org/apache/accumulo/master/replication/WorkDriver.java
----------------------------------------------------------------------
diff --git a/server/master/src/main/java/org/apache/accumulo/master/replication/WorkDriver.java b/server/master/src/main/java/org/apache/accumulo/master/replication/WorkDriver.java
index 975d06c..fbc9c80 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/replication/WorkDriver.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/replication/WorkDriver.java
@@ -16,6 +16,8 @@
*/
package org.apache.accumulo.master.replication;
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.apache.accumulo.core.client.Connector;
import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.conf.Property;
@@ -39,10 +41,10 @@ public class WorkDriver extends Daemon {
private WorkAssigner assigner;
private String assignerImplName;
- public WorkDriver(Master master, Connector conn) {
+ public WorkDriver(Master master) throws AccumuloException, AccumuloSecurityException {
super();
this.master = master;
- this.conn = conn;
+ this.conn = master.getConnector();
this.conf = master.getConfiguration();
configureWorkAssigner();
}