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 2013/09/07 05:28:05 UTC
[02/59] [abbrv] ACCUMULO-658 Move master to its own module
http://git-wip-us.apache.org/repos/asf/accumulo/blob/88079cc3/server/server/src/main/java/org/apache/accumulo/server/master/tableOps/Utils.java
----------------------------------------------------------------------
diff --git a/server/server/src/main/java/org/apache/accumulo/server/master/tableOps/Utils.java b/server/server/src/main/java/org/apache/accumulo/server/master/tableOps/Utils.java
deleted file mode 100644
index e57801c..0000000
--- a/server/server/src/main/java/org/apache/accumulo/server/master/tableOps/Utils.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * 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 org.apache.accumulo.server.master.tableOps;
-
-import java.math.BigInteger;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-
-import org.apache.accumulo.core.Constants;
-import org.apache.accumulo.core.client.Instance;
-import org.apache.accumulo.core.client.impl.Tables;
-import org.apache.accumulo.core.client.impl.thrift.TableOperation;
-import org.apache.accumulo.core.client.impl.thrift.TableOperationExceptionType;
-import org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException;
-import org.apache.accumulo.core.zookeeper.ZooUtil;
-import org.apache.accumulo.fate.zookeeper.DistributedReadWriteLock;
-import org.apache.accumulo.fate.zookeeper.IZooReaderWriter;
-import org.apache.accumulo.fate.zookeeper.IZooReaderWriter.Mutator;
-import org.apache.accumulo.fate.zookeeper.ZooReservation;
-import org.apache.accumulo.server.client.HdfsZooInstance;
-import org.apache.accumulo.server.zookeeper.ZooQueueLock;
-import org.apache.accumulo.server.zookeeper.ZooReaderWriter;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.log4j.Logger;
-import org.apache.zookeeper.KeeperException;
-
-public class Utils {
-
- static void checkTableDoesNotExist(Instance instance, String tableName, String tableId, TableOperation operation) throws ThriftTableOperationException {
-
- String id = Tables.getNameToIdMap(instance).get(tableName);
-
- if (id != null && !id.equals(tableId))
- throw new ThriftTableOperationException(null, tableName, operation, TableOperationExceptionType.EXISTS, null);
- }
-
- static String getNextTableId(String tableName, Instance instance) throws ThriftTableOperationException {
-
- String tableId = null;
- try {
- IZooReaderWriter zoo = ZooReaderWriter.getRetryingInstance();
- final String ntp = ZooUtil.getRoot(instance) + Constants.ZTABLES;
- byte[] nid = zoo.mutate(ntp, "0".getBytes(), ZooUtil.PUBLIC, new Mutator() {
- @Override
- public byte[] mutate(byte[] currentValue) throws Exception {
- BigInteger nextId = new BigInteger(new String(currentValue), Character.MAX_RADIX);
- nextId = nextId.add(BigInteger.ONE);
- return nextId.toString(Character.MAX_RADIX).getBytes();
- }
- });
- return new String(nid);
- } catch (Exception e1) {
- Logger.getLogger(CreateTable.class).error("Failed to assign tableId to " + tableName, e1);
- throw new ThriftTableOperationException(tableId, tableName, TableOperation.CREATE, TableOperationExceptionType.OTHER, e1.getMessage());
- }
- }
-
- static final Lock tableNameLock = new ReentrantLock();
- static final Lock idLock = new ReentrantLock();
- private static final Logger log = Logger.getLogger(Utils.class);
-
- public static long reserveTable(String tableId, long tid, boolean writeLock, boolean tableMustExist, TableOperation op) throws Exception {
- if (getLock(tableId, tid, writeLock).tryLock()) {
- if (tableMustExist) {
- Instance instance = HdfsZooInstance.getInstance();
- IZooReaderWriter zk = ZooReaderWriter.getRetryingInstance();
- if (!zk.exists(ZooUtil.getRoot(instance) + Constants.ZTABLES + "/" + tableId))
- throw new ThriftTableOperationException(tableId, "", op, TableOperationExceptionType.NOTFOUND, "Table does not exists");
- }
- log.info("table " + tableId + " (" + Long.toHexString(tid) + ") locked for " + (writeLock ? "write" : "read") + " operation: " + op);
- return 0;
- } else
- return 100;
- }
-
- public static void unreserveTable(String tableId, long tid, boolean writeLock) throws Exception {
- getLock(tableId, tid, writeLock).unlock();
- log.info("table " + tableId + " (" + Long.toHexString(tid) + ") unlocked for " + (writeLock ? "write" : "read"));
- }
-
- public static long reserveHdfsDirectory(String directory, long tid) throws KeeperException, InterruptedException {
- Instance instance = HdfsZooInstance.getInstance();
-
- String resvPath = ZooUtil.getRoot(instance) + Constants.ZHDFS_RESERVATIONS + "/" + new String(Base64.encodeBase64(directory.getBytes()));
-
- IZooReaderWriter zk = ZooReaderWriter.getRetryingInstance();
-
- if (ZooReservation.attempt(zk, resvPath, String.format("%016x", tid), "")) {
- return 0;
- } else
- return 50;
- }
-
- public static void unreserveHdfsDirectory(String directory, long tid) throws KeeperException, InterruptedException {
- Instance instance = HdfsZooInstance.getInstance();
- String resvPath = ZooUtil.getRoot(instance) + Constants.ZHDFS_RESERVATIONS + "/" + new String(Base64.encodeBase64(directory.getBytes()));
- ZooReservation.release(ZooReaderWriter.getRetryingInstance(), resvPath, String.format("%016x", tid));
- }
-
- private static Lock getLock(String tableId, long tid, boolean writeLock) throws Exception {
- byte[] lockData = String.format("%016x", tid).getBytes();
- ZooQueueLock qlock = new ZooQueueLock(ZooUtil.getRoot(HdfsZooInstance.getInstance()) + Constants.ZTABLE_LOCKS + "/" + tableId, false);
- Lock lock = DistributedReadWriteLock.recoverLock(qlock, lockData);
- if (lock == null) {
- DistributedReadWriteLock locker = new DistributedReadWriteLock(qlock, lockData);
- if (writeLock)
- lock = locker.writeLock();
- else
- lock = locker.readLock();
- }
- return lock;
- }
-
- public static Lock getReadLock(String tableId, long tid) throws Exception {
- return Utils.getLock(tableId, tid, false);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/88079cc3/server/server/src/main/java/org/apache/accumulo/server/master/tserverOps/ShutdownTServer.java
----------------------------------------------------------------------
diff --git a/server/server/src/main/java/org/apache/accumulo/server/master/tserverOps/ShutdownTServer.java b/server/server/src/main/java/org/apache/accumulo/server/master/tserverOps/ShutdownTServer.java
deleted file mode 100644
index d411ac4..0000000
--- a/server/server/src/main/java/org/apache/accumulo/server/master/tserverOps/ShutdownTServer.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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 org.apache.accumulo.server.master.tserverOps;
-
-import org.apache.accumulo.core.Constants;
-import org.apache.accumulo.core.master.thrift.TabletServerStatus;
-import org.apache.accumulo.core.util.AddressUtil;
-import org.apache.accumulo.core.zookeeper.ZooUtil;
-import org.apache.accumulo.fate.Repo;
-import org.apache.accumulo.fate.zookeeper.IZooReaderWriter;
-import org.apache.accumulo.fate.zookeeper.ZooUtil.NodeExistsPolicy;
-import org.apache.accumulo.server.master.EventCoordinator.Listener;
-import org.apache.accumulo.server.master.LiveTServerSet.TServerConnection;
-import org.apache.accumulo.server.master.Master;
-import org.apache.accumulo.server.master.state.TServerInstance;
-import org.apache.accumulo.server.master.tableOps.MasterRepo;
-import org.apache.accumulo.server.zookeeper.ZooLock;
-import org.apache.accumulo.server.zookeeper.ZooReaderWriter;
-import org.apache.log4j.Logger;
-import org.apache.thrift.transport.TTransportException;
-
-public class ShutdownTServer extends MasterRepo {
-
- private static final long serialVersionUID = 1L;
- private static final Logger log = Logger.getLogger(ShutdownTServer.class);
- private TServerInstance server;
- private boolean force;
-
- public ShutdownTServer(TServerInstance server, boolean force) {
- this.server = server;
- this.force = force;
- }
-
- @Override
- public long isReady(long tid, Master environment) throws Exception {
- return 0;
- }
-
- @Override
- public Repo<Master> call(long tid, Master master) throws Exception {
- // suppress assignment of tablets to the server
- if (force) {
- String tserver = AddressUtil.toString(server.getLocation());
- String path = ZooUtil.getRoot(master.getInstance()) + Constants.ZTSERVERS + "/" + tserver;
- ZooLock.deleteLock(path);
- path = ZooUtil.getRoot(master.getInstance()) + Constants.ZDEADTSERVERS + "/" + tserver;
- IZooReaderWriter zoo = ZooReaderWriter.getInstance();
- zoo.putPersistentData(path, "forced down".getBytes(), NodeExistsPolicy.OVERWRITE);
- return null;
- }
-
- // TODO move this to isReady() and drop while loop? - ACCUMULO-1259
- Listener listener = master.getEventCoordinator().getListener();
- master.shutdownTServer(server);
- while (master.onlineTabletServers().contains(server)) {
- TServerConnection connection = master.getConnection(server);
- if (connection != null) {
- try {
- TabletServerStatus status = connection.getTableMap(false);
- if (status.tableMap != null && status.tableMap.isEmpty()) {
- log.info("tablet server hosts no tablets " + server);
- connection.halt(master.getMasterLock());
- log.info("tablet server asked to halt " + server);
- break;
- }
- } catch (TTransportException ex) {
- // expected
- } catch (Exception ex) {
- log.error("Error talking to tablet server " + server + ": " + ex);
- }
- }
- listener.waitForEvents(1000);
- }
-
- return null;
- }
-
- @Override
- public void undo(long tid, Master m) throws Exception {}
-}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/88079cc3/server/server/src/main/java/org/apache/accumulo/server/tabletserver/Tablet.java
----------------------------------------------------------------------
diff --git a/server/server/src/main/java/org/apache/accumulo/server/tabletserver/Tablet.java b/server/server/src/main/java/org/apache/accumulo/server/tabletserver/Tablet.java
index f3cbe3c..6c1aca9 100644
--- a/server/server/src/main/java/org/apache/accumulo/server/tabletserver/Tablet.java
+++ b/server/server/src/main/java/org/apache/accumulo/server/tabletserver/Tablet.java
@@ -94,6 +94,8 @@ import org.apache.accumulo.core.util.LocalityGroupUtil.LocalityGroupConfiguratio
import org.apache.accumulo.core.util.Pair;
import org.apache.accumulo.core.util.UtilWaitThread;
import org.apache.accumulo.fate.zookeeper.IZooReaderWriter;
+import org.apache.accumulo.master.state.TServerInstance;
+import org.apache.accumulo.master.tableOps.CompactRange.CompactionIterators;
import org.apache.accumulo.server.ServerConstants;
import org.apache.accumulo.server.client.HdfsZooInstance;
import org.apache.accumulo.server.conf.TableConfiguration;
@@ -101,8 +103,6 @@ import org.apache.accumulo.server.constraints.ConstraintChecker;
import org.apache.accumulo.server.fs.FileRef;
import org.apache.accumulo.server.fs.VolumeManager;
import org.apache.accumulo.server.fs.VolumeManagerImpl;
-import org.apache.accumulo.server.master.state.TServerInstance;
-import org.apache.accumulo.server.master.tableOps.CompactRange.CompactionIterators;
import org.apache.accumulo.server.problems.ProblemReport;
import org.apache.accumulo.server.problems.ProblemReports;
import org.apache.accumulo.server.problems.ProblemType;
http://git-wip-us.apache.org/repos/asf/accumulo/blob/88079cc3/server/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletServer.java
----------------------------------------------------------------------
diff --git a/server/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletServer.java b/server/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletServer.java
index 41e43ab..c01c92d 100644
--- a/server/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletServer.java
+++ b/server/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletServer.java
@@ -140,6 +140,13 @@ import org.apache.accumulo.fate.zookeeper.IZooReaderWriter;
import org.apache.accumulo.fate.zookeeper.ZooLock.LockLossReason;
import org.apache.accumulo.fate.zookeeper.ZooLock.LockWatcher;
import org.apache.accumulo.fate.zookeeper.ZooUtil.NodeExistsPolicy;
+import org.apache.accumulo.master.state.Assignment;
+import org.apache.accumulo.master.state.DistributedStoreException;
+import org.apache.accumulo.master.state.TServerInstance;
+import org.apache.accumulo.master.state.TabletLocationState;
+import org.apache.accumulo.master.state.TabletStateStore;
+import org.apache.accumulo.master.state.ZooTabletStateStore;
+import org.apache.accumulo.master.state.TabletLocationState.BadLocationStateException;
import org.apache.accumulo.server.Accumulo;
import org.apache.accumulo.server.ServerConstants;
import org.apache.accumulo.server.ServerOpts;
@@ -152,13 +159,6 @@ import org.apache.accumulo.server.data.ServerMutation;
import org.apache.accumulo.server.fs.FileRef;
import org.apache.accumulo.server.fs.VolumeManager;
import org.apache.accumulo.server.fs.VolumeManagerImpl;
-import org.apache.accumulo.server.master.state.Assignment;
-import org.apache.accumulo.server.master.state.DistributedStoreException;
-import org.apache.accumulo.server.master.state.TServerInstance;
-import org.apache.accumulo.server.master.state.TabletLocationState;
-import org.apache.accumulo.server.master.state.TabletLocationState.BadLocationStateException;
-import org.apache.accumulo.server.master.state.TabletStateStore;
-import org.apache.accumulo.server.master.state.ZooTabletStateStore;
import org.apache.accumulo.server.metrics.AbstractMetricsImpl;
import org.apache.accumulo.server.problems.ProblemReport;
import org.apache.accumulo.server.problems.ProblemReports;
http://git-wip-us.apache.org/repos/asf/accumulo/blob/88079cc3/server/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletTime.java
----------------------------------------------------------------------
diff --git a/server/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletTime.java b/server/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletTime.java
deleted file mode 100644
index c7cfc59..0000000
--- a/server/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletTime.java
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- * 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 org.apache.accumulo.server.tabletserver;
-
-import java.util.List;
-import java.util.concurrent.atomic.AtomicLong;
-
-import org.apache.accumulo.core.client.admin.TimeType;
-import org.apache.accumulo.core.data.Mutation;
-import org.apache.accumulo.server.data.ServerMutation;
-import org.apache.accumulo.server.util.time.RelativeTime;
-
-public abstract class TabletTime {
- public static final char LOGICAL_TIME_ID = 'L';
- public static final char MILLIS_TIME_ID = 'M';
-
- public static char getTimeID(TimeType timeType) {
- switch (timeType) {
- case LOGICAL:
- return LOGICAL_TIME_ID;
- case MILLIS:
- return MILLIS_TIME_ID;
- }
-
- throw new IllegalArgumentException("Unknown time type " + timeType);
- }
-
- abstract void useMaxTimeFromWALog(long time);
-
- abstract String getMetadataValue(long time);
-
- abstract String getMetadataValue();
-
- // abstract long setUpdateTimes(Mutation mutation);
- abstract long setUpdateTimes(List<Mutation> mutations);
-
- abstract long getTime();
-
- abstract long getAndUpdateTime();
-
- protected void setSystemTimes(Mutation mutation, long lastCommitTime) {
- ServerMutation m = (ServerMutation)mutation;
- m.setSystemTimestamp(lastCommitTime);
- }
-
- static TabletTime getInstance(String metadataValue) {
- if (metadataValue.charAt(0) == LOGICAL_TIME_ID) {
- return new LogicalTime(Long.parseLong(metadataValue.substring(1)));
- } else if (metadataValue.charAt(0) == MILLIS_TIME_ID) {
- return new MillisTime(Long.parseLong(metadataValue.substring(1)));
- }
-
- throw new IllegalArgumentException("Time type unknown : " + metadataValue);
-
- }
-
- public static String maxMetadataTime(String mv1, String mv2) {
- if (mv1 == null) {
- checkType(mv2);
- return mv2;
- }
-
- if (mv2 == null) {
- checkType(mv1);
- return mv1;
- }
-
- if (mv1.charAt(0) != mv2.charAt(0)) throw new IllegalArgumentException("Time types differ " + mv1 + " " + mv2);
- checkType(mv1);
-
- long t1 = Long.parseLong(mv1.substring(1));
- long t2 = Long.parseLong(mv2.substring(1));
-
- if (t1 < t2) return mv2;
- else return mv1;
-
- }
-
- private static void checkType(String mv1) {
- if (mv1.charAt(0) != LOGICAL_TIME_ID && mv1.charAt(0) != MILLIS_TIME_ID) throw new IllegalArgumentException("Invalid time type " + mv1);
- }
-
- static class MillisTime extends TabletTime {
-
- private long lastTime;
- private long lastUpdateTime = 0;
-
- public MillisTime(long time) {
- this.lastTime = time;
- }
-
- @Override
- String getMetadataValue(long time) {
- return MILLIS_TIME_ID + "" + time;
- }
-
- @Override
- public String getMetadataValue() {
- return getMetadataValue(lastTime);
- }
-
- @Override
- void useMaxTimeFromWALog(long time) {
- if (time > lastTime)
- lastTime = time;
- }
-
- @Override
- long setUpdateTimes(List<Mutation> mutations) {
-
- long currTime = RelativeTime.currentTimeMillis();
-
- synchronized (this) {
- if (mutations.size() == 0)
- return lastTime;
-
- currTime = updateTime(currTime);
- }
-
- for (Mutation mutation : mutations)
- setSystemTimes(mutation, currTime);
-
- return currTime;
- }
-
- private long updateTime(long currTime) {
- if (currTime < lastTime) {
- if (currTime - lastUpdateTime > 0) {
- // not in same millisecond as last call
- // to this method so move ahead slowly
- lastTime++;
- }
-
- lastUpdateTime = currTime;
-
- currTime = lastTime;
- } else {
- lastTime = currTime;
- }
- return currTime;
- }
-
- @Override
- long getTime() {
- return lastTime;
- }
-
- @Override
- long getAndUpdateTime() {
- long currTime = RelativeTime.currentTimeMillis();
-
- synchronized (this) {
- currTime = updateTime(currTime);
- }
-
- return currTime;
- }
-
- }
-
- static class LogicalTime extends TabletTime {
- AtomicLong nextTime;
-
- private LogicalTime(Long time) {
- this.nextTime = new AtomicLong(time.longValue() + 1);
- }
-
- @Override
- void useMaxTimeFromWALog(long time) {
- time++;
-
- if (this.nextTime.get() < time) {
- this.nextTime.set(time);
- }
- }
-
- @Override
- public String getMetadataValue() {
- return getMetadataValue(getTime());
- }
-
- @Override
- public String getMetadataValue(long time) {
- return LOGICAL_TIME_ID + "" + time;
- }
-
- @Override
- long setUpdateTimes(List<Mutation> mutations) {
- if (mutations.size() == 0)
- return getTime();
-
- long time = nextTime.getAndAdd(mutations.size());
- for (Mutation mutation : mutations)
- setSystemTimes(mutation, time++);
-
- return time - 1;
- }
-
- @Override
- long getTime() {
- return nextTime.get() - 1;
- }
-
- @Override
- long getAndUpdateTime() {
- return nextTime.getAndIncrement();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/88079cc3/server/server/src/main/java/org/apache/accumulo/server/tabletserver/UniqueNameAllocator.java
----------------------------------------------------------------------
diff --git a/server/server/src/main/java/org/apache/accumulo/server/tabletserver/UniqueNameAllocator.java b/server/server/src/main/java/org/apache/accumulo/server/tabletserver/UniqueNameAllocator.java
deleted file mode 100644
index 9629948..0000000
--- a/server/server/src/main/java/org/apache/accumulo/server/tabletserver/UniqueNameAllocator.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * 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 org.apache.accumulo.server.tabletserver;
-
-import java.util.Random;
-
-import org.apache.accumulo.core.Constants;
-import org.apache.accumulo.core.util.FastFormat;
-import org.apache.accumulo.core.zookeeper.ZooUtil;
-import org.apache.accumulo.server.client.HdfsZooInstance;
-import org.apache.accumulo.server.zookeeper.ZooReaderWriter;
-
-/**
- * Allocates unique names for an accumulo instance. The names are unique for the lifetime of the instance.
- *
- * This is useful for filenames because it makes caching easy.
- *
- */
-
-public class UniqueNameAllocator {
- private long next = 0;
- private long maxAllocated = 0;
- private String nextNamePath;
- private Random rand;
-
- private UniqueNameAllocator() {
- nextNamePath = Constants.ZROOT + "/" + HdfsZooInstance.getInstance().getInstanceID() + Constants.ZNEXT_FILE;
- rand = new Random();
- }
-
- public synchronized String getNextName() {
-
- while (next >= maxAllocated) {
- final int allocate = 100 + rand.nextInt(100);
-
- try {
- byte[] max = ZooReaderWriter.getRetryingInstance().mutate(nextNamePath, null, ZooUtil.PRIVATE, new ZooReaderWriter.Mutator() {
- public byte[] mutate(byte[] currentValue) throws Exception {
- long l = Long.parseLong(new String(currentValue), Character.MAX_RADIX);
- l += allocate;
- return Long.toString(l, Character.MAX_RADIX).getBytes();
- }
- });
-
- maxAllocated = Long.parseLong(new String(max), Character.MAX_RADIX);
- next = maxAllocated - allocate;
-
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- return new String(FastFormat.toZeroPaddedString(next++, 7, Character.MAX_RADIX, new byte[0]));
- }
-
- private static UniqueNameAllocator instance = null;
-
- public static synchronized UniqueNameAllocator getInstance() {
- if (instance == null)
- instance = new UniqueNameAllocator();
-
- return instance;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/88079cc3/server/server/src/main/java/org/apache/accumulo/server/tabletserver/log/DfsLogger.java
----------------------------------------------------------------------
diff --git a/server/server/src/main/java/org/apache/accumulo/server/tabletserver/log/DfsLogger.java b/server/server/src/main/java/org/apache/accumulo/server/tabletserver/log/DfsLogger.java
index 6d574b9..52959b3 100644
--- a/server/server/src/main/java/org/apache/accumulo/server/tabletserver/log/DfsLogger.java
+++ b/server/server/src/main/java/org/apache/accumulo/server/tabletserver/log/DfsLogger.java
@@ -44,11 +44,11 @@ import org.apache.accumulo.core.security.crypto.CryptoModuleFactory;
import org.apache.accumulo.core.security.crypto.CryptoModuleParameters;
import org.apache.accumulo.core.util.Daemon;
import org.apache.accumulo.core.util.StringUtil;
+import org.apache.accumulo.master.state.TServerInstance;
import org.apache.accumulo.server.ServerConstants;
import org.apache.accumulo.server.fs.VolumeManager;
import org.apache.accumulo.server.logger.LogFileKey;
import org.apache.accumulo.server.logger.LogFileValue;
-import org.apache.accumulo.server.master.state.TServerInstance;
import org.apache.accumulo.server.tabletserver.TabletMutations;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
http://git-wip-us.apache.org/repos/asf/accumulo/blob/88079cc3/server/server/src/main/java/org/apache/accumulo/server/util/FindOfflineTablets.java
----------------------------------------------------------------------
diff --git a/server/server/src/main/java/org/apache/accumulo/server/util/FindOfflineTablets.java b/server/server/src/main/java/org/apache/accumulo/server/util/FindOfflineTablets.java
index 13f1b16..d7837b8 100644
--- a/server/server/src/main/java/org/apache/accumulo/server/util/FindOfflineTablets.java
+++ b/server/server/src/main/java/org/apache/accumulo/server/util/FindOfflineTablets.java
@@ -32,15 +32,15 @@ import org.apache.accumulo.core.metadata.MetadataTable;
import org.apache.accumulo.core.metadata.RootTable;
import org.apache.accumulo.core.metadata.schema.MetadataSchema;
import org.apache.accumulo.core.security.Credentials;
+import org.apache.accumulo.master.LiveTServerSet;
+import org.apache.accumulo.master.LiveTServerSet.Listener;
+import org.apache.accumulo.master.state.DistributedStoreException;
+import org.apache.accumulo.master.state.MetaDataTableScanner;
+import org.apache.accumulo.master.state.TServerInstance;
+import org.apache.accumulo.master.state.TabletLocationState;
+import org.apache.accumulo.master.state.TabletState;
+import org.apache.accumulo.master.state.ZooTabletStateStore;
import org.apache.accumulo.server.cli.ClientOpts;
-import org.apache.accumulo.server.master.LiveTServerSet;
-import org.apache.accumulo.server.master.LiveTServerSet.Listener;
-import org.apache.accumulo.server.master.state.DistributedStoreException;
-import org.apache.accumulo.server.master.state.MetaDataTableScanner;
-import org.apache.accumulo.server.master.state.TServerInstance;
-import org.apache.accumulo.server.master.state.TabletLocationState;
-import org.apache.accumulo.server.master.state.TabletState;
-import org.apache.accumulo.server.master.state.ZooTabletStateStore;
import org.apache.accumulo.server.security.SystemCredentials;
import org.apache.accumulo.server.tables.TableManager;
import org.apache.hadoop.io.Text;
http://git-wip-us.apache.org/repos/asf/accumulo/blob/88079cc3/server/server/src/main/java/org/apache/accumulo/server/util/MasterMetadataUtil.java
----------------------------------------------------------------------
diff --git a/server/server/src/main/java/org/apache/accumulo/server/util/MasterMetadataUtil.java b/server/server/src/main/java/org/apache/accumulo/server/util/MasterMetadataUtil.java
index 987eba9..952d272 100644
--- a/server/server/src/main/java/org/apache/accumulo/server/util/MasterMetadataUtil.java
+++ b/server/server/src/main/java/org/apache/accumulo/server/util/MasterMetadataUtil.java
@@ -48,11 +48,11 @@ import org.apache.accumulo.core.util.ColumnFQ;
import org.apache.accumulo.core.util.UtilWaitThread;
import org.apache.accumulo.fate.zookeeper.IZooReaderWriter;
import org.apache.accumulo.fate.zookeeper.ZooUtil.NodeMissingPolicy;
+import org.apache.accumulo.master.state.TServerInstance;
import org.apache.accumulo.server.client.HdfsZooInstance;
import org.apache.accumulo.server.fs.FileRef;
import org.apache.accumulo.server.fs.VolumeManager;
import org.apache.accumulo.server.fs.VolumeManagerImpl;
-import org.apache.accumulo.server.master.state.TServerInstance;
import org.apache.accumulo.server.zookeeper.ZooLock;
import org.apache.accumulo.server.zookeeper.ZooReaderWriter;
import org.apache.hadoop.io.Text;
http://git-wip-us.apache.org/repos/asf/accumulo/blob/88079cc3/server/server/src/main/java/org/apache/accumulo/server/util/TabletOperations.java
----------------------------------------------------------------------
diff --git a/server/server/src/main/java/org/apache/accumulo/server/util/TabletOperations.java b/server/server/src/main/java/org/apache/accumulo/server/util/TabletOperations.java
deleted file mode 100644
index 8dac384..0000000
--- a/server/server/src/main/java/org/apache/accumulo/server/util/TabletOperations.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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 org.apache.accumulo.server.util;
-
-import java.io.IOException;
-
-import org.apache.accumulo.core.Constants;
-import org.apache.accumulo.core.util.UtilWaitThread;
-import org.apache.accumulo.server.ServerConstants;
-import org.apache.accumulo.server.fs.VolumeManager;
-import org.apache.accumulo.server.fs.VolumeManagerImpl;
-import org.apache.accumulo.server.tabletserver.UniqueNameAllocator;
-import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.io.Text;
-import org.apache.log4j.Logger;
-
-public class TabletOperations {
-
- private static final Logger log = Logger.getLogger(TabletOperations.class);
-
- public static String createTabletDirectory(VolumeManager fs, String tableId, Text endRow) {
- String lowDirectory;
-
- UniqueNameAllocator namer = UniqueNameAllocator.getInstance();
- String volume = fs.choose(ServerConstants.getTablesDirs());
-
- while (true) {
- try {
- if (endRow == null) {
- lowDirectory = Constants.DEFAULT_TABLET_LOCATION;
- Path lowDirectoryPath = new Path(volume + "/" + tableId + "/" + lowDirectory);
- if (fs.exists(lowDirectoryPath) || fs.mkdirs(lowDirectoryPath))
- return lowDirectoryPath.makeQualified(fs.getFileSystemByPath(lowDirectoryPath)).toString();
- log.warn("Failed to create " + lowDirectoryPath + " for unknown reason");
- } else {
- lowDirectory = "/" + Constants.GENERATED_TABLET_DIRECTORY_PREFIX + namer.getNextName();
- Path lowDirectoryPath = new Path(volume + "/" + tableId + "/" + lowDirectory);
- if (fs.exists(lowDirectoryPath))
- throw new IllegalStateException("Dir exist when it should not " + lowDirectoryPath);
- if (fs.mkdirs(lowDirectoryPath))
- return lowDirectoryPath.makeQualified(fs.getFileSystemByPath(lowDirectoryPath)).toString();
- }
- } catch (IOException e) {
- log.warn(e);
- }
-
- log.warn("Failed to create dir for tablet in table " + tableId + " in volume " + volume + " + will retry ...");
- UtilWaitThread.sleep(3000);
-
- }
- }
-
- public static String createTabletDirectory(String tableDir, Text endRow) {
- while (true) {
- try {
- VolumeManager fs = VolumeManagerImpl.get();
- return createTabletDirectory(fs, tableDir, endRow);
- } catch (IOException e) {
- log.warn(e);
- }
- UtilWaitThread.sleep(3000);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/88079cc3/server/server/src/test/java/org/apache/accumulo/server/master/DefaultMapTest.java
----------------------------------------------------------------------
diff --git a/server/server/src/test/java/org/apache/accumulo/server/master/DefaultMapTest.java b/server/server/src/test/java/org/apache/accumulo/server/master/DefaultMapTest.java
deleted file mode 100644
index efa39e7..0000000
--- a/server/server/src/test/java/org/apache/accumulo/server/master/DefaultMapTest.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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 org.apache.accumulo.server.master;
-
-import org.apache.accumulo.server.util.DefaultMap;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-public class DefaultMapTest {
-
- @Test
- public void testDefaultMap() {
- DefaultMap<String,String> map = new DefaultMap<String,String>("");
- map.put("key", "value");
- String empty = map.get("otherKey");
- assertEquals(map.get("key"), "value");
- assertEquals(empty, "");
- assertTrue(empty == map.get("otherKey"));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/88079cc3/server/server/src/test/java/org/apache/accumulo/server/master/TestMergeState.java
----------------------------------------------------------------------
diff --git a/server/server/src/test/java/org/apache/accumulo/server/master/TestMergeState.java b/server/server/src/test/java/org/apache/accumulo/server/master/TestMergeState.java
deleted file mode 100644
index 48e1e14..0000000
--- a/server/server/src/test/java/org/apache/accumulo/server/master/TestMergeState.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * 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 org.apache.accumulo.server.master;
-
-import java.net.InetSocketAddress;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Set;
-
-import org.apache.accumulo.core.client.BatchDeleter;
-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.client.mock.MockInstance;
-import org.apache.accumulo.core.client.security.tokens.PasswordToken;
-import org.apache.accumulo.core.data.KeyExtent;
-import org.apache.accumulo.core.data.Mutation;
-import org.apache.accumulo.core.data.Range;
-import org.apache.accumulo.core.data.Value;
-import org.apache.accumulo.core.metadata.MetadataTable;
-import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection;
-import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ChoppedColumnFamily;
-import org.apache.accumulo.core.security.Authorizations;
-import org.apache.accumulo.core.security.Credentials;
-import org.apache.accumulo.server.master.state.Assignment;
-import org.apache.accumulo.server.master.state.CurrentState;
-import org.apache.accumulo.server.master.state.MergeInfo;
-import org.apache.accumulo.server.master.state.MergeState;
-import org.apache.accumulo.server.master.state.MergeStats;
-import org.apache.accumulo.server.master.state.MetaDataStateStore;
-import org.apache.accumulo.server.master.state.TServerInstance;
-import org.apache.accumulo.server.master.state.TabletLocationState;
-import org.apache.accumulo.server.master.state.TabletState;
-import org.apache.hadoop.io.Text;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- *
- */
-public class TestMergeState {
-
- class MockCurrentState implements CurrentState {
-
- TServerInstance someTServer = new TServerInstance(new InetSocketAddress("127.0.0.1", 1234), 0x123456);
- MergeInfo mergeInfo;
-
- MockCurrentState(MergeInfo info) {
- this.mergeInfo = info;
- }
-
- @Override
- public Set<String> onlineTables() {
- return Collections.singleton("t");
- }
-
- @Override
- public Set<TServerInstance> onlineTabletServers() {
- return Collections.singleton(someTServer);
- }
-
- @Override
- public Collection<MergeInfo> merges() {
- return Collections.singleton(mergeInfo);
- }
- }
-
- private static void update(Connector c, Mutation m) throws TableNotFoundException, MutationsRejectedException {
- BatchWriter bw = c.createBatchWriter(MetadataTable.NAME, new BatchWriterConfig());
- bw.addMutation(m);
- bw.close();
- }
-
- @Test
- public void test() throws Exception {
- Instance instance = new MockInstance();
- Connector connector = instance.getConnector("root", new PasswordToken(""));
- BatchWriter bw = connector.createBatchWriter("!METADATA", new BatchWriterConfig());
-
- // Create a fake METADATA table with these splits
- String splits[] = {"a", "e", "j", "o", "t", "z"};
- // create metadata for a table "t" with the splits above
- Text tableId = new Text("t");
- Text pr = null;
- for (String s : splits) {
- Text split = new Text(s);
- Mutation prevRow = KeyExtent.getPrevRowUpdateMutation(new KeyExtent(tableId, split, pr));
- prevRow.put(TabletsSection.CurrentLocationColumnFamily.NAME, new Text("123456"), new Value("127.0.0.1:1234".getBytes()));
- ChoppedColumnFamily.CHOPPED_COLUMN.put(prevRow, new Value("junk".getBytes()));
- bw.addMutation(prevRow);
- pr = split;
- }
- // Add the default tablet
- Mutation defaultTablet = KeyExtent.getPrevRowUpdateMutation(new KeyExtent(tableId, null, pr));
- defaultTablet.put(TabletsSection.CurrentLocationColumnFamily.NAME, new Text("123456"), new Value("127.0.0.1:1234".getBytes()));
- bw.addMutation(defaultTablet);
- bw.close();
-
- // Read out the TabletLocationStates
- MockCurrentState state = new MockCurrentState(new MergeInfo(new KeyExtent(tableId, new Text("p"), new Text("e")), MergeInfo.Operation.MERGE));
- Credentials credentials = new Credentials("root", new PasswordToken(new byte[0]));
-
- // Verify the tablet state: hosted, and count
- MetaDataStateStore metaDataStateStore = new MetaDataStateStore(instance, credentials, state);
- int count = 0;
- for (TabletLocationState tss : metaDataStateStore) {
- Assert.assertEquals(TabletState.HOSTED, tss.getState(state.onlineTabletServers()));
- count++;
- }
- Assert.assertEquals(splits.length + 1, count);
-
- // Create the hole
- // Split the tablet at one end of the range
- Mutation m = new KeyExtent(tableId, new Text("t"), new Text("p")).getPrevRowUpdateMutation();
- TabletsSection.TabletColumnFamily.SPLIT_RATIO_COLUMN.put(m, new Value("0.5".getBytes()));
- TabletsSection.TabletColumnFamily.OLD_PREV_ROW_COLUMN.put(m, KeyExtent.encodePrevEndRow(new Text("o")));
- update(connector, m);
-
- // do the state check
- MergeStats stats = scan(state, metaDataStateStore);
- MergeState newState = stats.nextMergeState(connector, state);
- Assert.assertEquals(MergeState.WAITING_FOR_OFFLINE, newState);
-
- // unassign the tablets
- BatchDeleter deleter = connector.createBatchDeleter("!METADATA", Authorizations.EMPTY, 1000, new BatchWriterConfig());
- deleter.fetchColumnFamily(TabletsSection.CurrentLocationColumnFamily.NAME);
- deleter.setRanges(Collections.singletonList(new Range()));
- deleter.delete();
-
- // now we should be ready to merge but, we have an inconsistent !METADATA table
- stats = scan(state, metaDataStateStore);
- Assert.assertEquals(MergeState.WAITING_FOR_OFFLINE, stats.nextMergeState(connector, state));
-
- // finish the split
- KeyExtent tablet = new KeyExtent(tableId, new Text("p"), new Text("o"));
- m = tablet.getPrevRowUpdateMutation();
- TabletsSection.TabletColumnFamily.SPLIT_RATIO_COLUMN.put(m, new Value("0.5".getBytes()));
- update(connector, m);
- metaDataStateStore.setLocations(Collections.singletonList(new Assignment(tablet, state.someTServer)));
-
- // onos... there's a new tablet online
- stats = scan(state, metaDataStateStore);
- Assert.assertEquals(MergeState.WAITING_FOR_CHOPPED, stats.nextMergeState(connector, state));
-
- // chop it
- m = tablet.getPrevRowUpdateMutation();
- ChoppedColumnFamily.CHOPPED_COLUMN.put(m, new Value("junk".getBytes()));
- update(connector, m);
-
- stats = scan(state, metaDataStateStore);
- Assert.assertEquals(MergeState.WAITING_FOR_OFFLINE, stats.nextMergeState(connector, state));
-
- // take it offline
- m = tablet.getPrevRowUpdateMutation();
- Collection<Collection<String>> walogs = Collections.emptyList();
- metaDataStateStore.unassign(Collections.singletonList(new TabletLocationState(tablet, null, state.someTServer, null, walogs, false)));
-
- // now we can split
- stats = scan(state, metaDataStateStore);
- Assert.assertEquals(MergeState.MERGING, stats.nextMergeState(connector, state));
-
- }
-
- /**
- * @param state
- * @param metaDataStateStore
- * @param locations
- * @return
- */
- private MergeStats scan(MockCurrentState state, MetaDataStateStore metaDataStateStore) {
- MergeStats stats = new MergeStats(state.mergeInfo);
- stats.getMergeInfo().setState(MergeState.WAITING_FOR_OFFLINE);
- for (TabletLocationState tss : metaDataStateStore) {
- stats.update(tss.extent, tss.getState(state.onlineTabletServers()), tss.chopped, false);
- }
- return stats;
- }
-}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/88079cc3/server/server/src/test/java/org/apache/accumulo/server/master/balancer/ChaoticLoadBalancerTest.java
----------------------------------------------------------------------
diff --git a/server/server/src/test/java/org/apache/accumulo/server/master/balancer/ChaoticLoadBalancerTest.java b/server/server/src/test/java/org/apache/accumulo/server/master/balancer/ChaoticLoadBalancerTest.java
deleted file mode 100644
index c6b4626..0000000
--- a/server/server/src/test/java/org/apache/accumulo/server/master/balancer/ChaoticLoadBalancerTest.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * 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 org.apache.accumulo.server.master.balancer;
-
-import static org.junit.Assert.assertEquals;
-
-import java.net.InetSocketAddress;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
-import org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException;
-import org.apache.accumulo.core.data.KeyExtent;
-import org.apache.accumulo.core.master.thrift.TableInfo;
-import org.apache.accumulo.core.master.thrift.TabletServerStatus;
-import org.apache.accumulo.core.tabletserver.thrift.TabletStats;
-import org.apache.accumulo.core.util.AddressUtil;
-import org.apache.accumulo.server.master.state.TServerInstance;
-import org.apache.accumulo.server.master.state.TabletMigration;
-import org.apache.hadoop.io.Text;
-import org.apache.thrift.TException;
-import org.junit.Test;
-
-public class ChaoticLoadBalancerTest {
-
- class FakeTServer {
- List<KeyExtent> extents = new ArrayList<KeyExtent>();
-
- TabletServerStatus getStatus(TServerInstance server) {
- TabletServerStatus result = new TabletServerStatus();
- result.tableMap = new HashMap<String,TableInfo>();
- for (KeyExtent extent : extents) {
- String table = extent.getTableId().toString();
- TableInfo info = result.tableMap.get(table);
- if (info == null)
- result.tableMap.put(table, info = new TableInfo());
- info.onlineTablets++;
- info.recs = info.onlineTablets;
- info.ingestRate = 123.;
- info.queryRate = 456.;
- }
- return result;
- }
- }
-
- Map<TServerInstance,FakeTServer> servers = new HashMap<TServerInstance,FakeTServer>();
-
- class TestChaoticLoadBalancer extends ChaoticLoadBalancer {
-
- @Override
- public List<TabletStats> getOnlineTabletsForTable(TServerInstance tserver, String table) throws ThriftSecurityException, TException {
- List<TabletStats> result = new ArrayList<TabletStats>();
- for (KeyExtent extent : servers.get(tserver).extents) {
- if (extent.getTableId().toString().equals(table)) {
- result.add(new TabletStats(extent.toThrift(), null, null, null, 0l, 0., 0., 0));
- }
- }
- return result;
- }
- }
-
- @Test
- public void testAssignMigrations() {
- servers.clear();
- servers.put(new TServerInstance(AddressUtil.parseAddress("127.0.0.1", 1234), "a"), new FakeTServer());
- servers.put(new TServerInstance(AddressUtil.parseAddress("127.0.0.1", 1235), "b"), new FakeTServer());
- servers.put(new TServerInstance(AddressUtil.parseAddress("127.0.0.1", 1236), "c"), new FakeTServer());
- Map<KeyExtent,TServerInstance> metadataTable = new TreeMap<KeyExtent,TServerInstance>();
- String table = "t1";
- metadataTable.put(makeExtent(table, null, null), null);
- table = "t2";
- metadataTable.put(makeExtent(table, "a", null), null);
- metadataTable.put(makeExtent(table, null, "a"), null);
- table = "t3";
- metadataTable.put(makeExtent(table, "a", null), null);
- metadataTable.put(makeExtent(table, "b", "a"), null);
- metadataTable.put(makeExtent(table, "c", "b"), null);
- metadataTable.put(makeExtent(table, "d", "c"), null);
- metadataTable.put(makeExtent(table, "e", "d"), null);
- metadataTable.put(makeExtent(table, null, "e"), null);
-
- TestChaoticLoadBalancer balancer = new TestChaoticLoadBalancer();
-
- SortedMap<TServerInstance,TabletServerStatus> current = new TreeMap<TServerInstance,TabletServerStatus>();
- for (Entry<TServerInstance,FakeTServer> entry : servers.entrySet()) {
- current.put(entry.getKey(), entry.getValue().getStatus(entry.getKey()));
- }
-
- Map<KeyExtent,TServerInstance> assignments = new HashMap<KeyExtent,TServerInstance>();
- balancer.getAssignments(getAssignments(servers), metadataTable, assignments);
-
- assertEquals(assignments.size(), metadataTable.size());
- }
-
- SortedMap<TServerInstance,TabletServerStatus> getAssignments(Map<TServerInstance,FakeTServer> servers) {
- SortedMap<TServerInstance,TabletServerStatus> result = new TreeMap<TServerInstance,TabletServerStatus>();
- for (Entry<TServerInstance,FakeTServer> entry : servers.entrySet()) {
- result.put(entry.getKey(), entry.getValue().getStatus(entry.getKey()));
- }
- return result;
- }
-
- @Test
- public void testUnevenAssignment() {
- servers.clear();
- for (char c : "abcdefghijklmnopqrstuvwxyz".toCharArray()) {
- String cString = Character.toString(c);
- InetSocketAddress fakeAddress = AddressUtil.parseAddress("127.0.0.1", c);
- String fakeInstance = cString;
- TServerInstance tsi = new TServerInstance(fakeAddress, fakeInstance);
- FakeTServer fakeTServer = new FakeTServer();
- servers.put(tsi, fakeTServer);
- fakeTServer.extents.add(makeExtent(cString, null, null));
- }
- // Put more tablets on one server, but not more than the number of servers
- Entry<TServerInstance,FakeTServer> first = servers.entrySet().iterator().next();
- first.getValue().extents.add(makeExtent("newTable", "a", null));
- first.getValue().extents.add(makeExtent("newTable", "b", "a"));
- first.getValue().extents.add(makeExtent("newTable", "c", "b"));
- first.getValue().extents.add(makeExtent("newTable", "d", "c"));
- first.getValue().extents.add(makeExtent("newTable", "e", "d"));
- first.getValue().extents.add(makeExtent("newTable", "f", "e"));
- first.getValue().extents.add(makeExtent("newTable", "g", "f"));
- first.getValue().extents.add(makeExtent("newTable", "h", "g"));
- first.getValue().extents.add(makeExtent("newTable", "i", null));
- TestChaoticLoadBalancer balancer = new TestChaoticLoadBalancer();
- Set<KeyExtent> migrations = Collections.emptySet();
-
- // Just want to make sure it gets some migrations, randomness prevents guarantee of a defined amount, or even expected amount
- List<TabletMigration> migrationsOut = new ArrayList<TabletMigration>();
- while (migrationsOut.size() != 0) {
- balancer.balance(getAssignments(servers), migrations, migrationsOut);
- }
- }
-
- private static KeyExtent makeExtent(String table, String end, String prev) {
- return new KeyExtent(new Text(table), toText(end), toText(prev));
- }
-
- private static Text toText(String value) {
- if (value != null)
- return new Text(value);
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/88079cc3/server/server/src/test/java/org/apache/accumulo/server/master/balancer/DefaultLoadBalancerTest.java
----------------------------------------------------------------------
diff --git a/server/server/src/test/java/org/apache/accumulo/server/master/balancer/DefaultLoadBalancerTest.java b/server/server/src/test/java/org/apache/accumulo/server/master/balancer/DefaultLoadBalancerTest.java
deleted file mode 100644
index 2dddbc4..0000000
--- a/server/server/src/test/java/org/apache/accumulo/server/master/balancer/DefaultLoadBalancerTest.java
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
- * 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 org.apache.accumulo.server.master.balancer;
-
-import static org.junit.Assert.*;
-
-import java.net.InetSocketAddress;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.TreeMap;
-import java.util.Map.Entry;
-
-import org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException;
-import org.apache.accumulo.core.data.KeyExtent;
-import org.apache.accumulo.core.master.thrift.TableInfo;
-import org.apache.accumulo.core.master.thrift.TabletServerStatus;
-import org.apache.accumulo.core.tabletserver.thrift.TabletStats;
-import org.apache.accumulo.core.util.AddressUtil;
-import org.apache.accumulo.server.master.balancer.DefaultLoadBalancer;
-import org.apache.accumulo.server.master.state.TServerInstance;
-import org.apache.accumulo.server.master.state.TabletMigration;
-import org.apache.hadoop.io.Text;
-import org.apache.thrift.TException;
-import org.junit.Test;
-
-public class DefaultLoadBalancerTest {
-
- class FakeTServer {
- List<KeyExtent> extents = new ArrayList<KeyExtent>();
-
- TabletServerStatus getStatus(TServerInstance server) {
- TabletServerStatus result = new TabletServerStatus();
- result.tableMap = new HashMap<String,TableInfo>();
- for (KeyExtent extent : extents) {
- String table = extent.getTableId().toString();
- TableInfo info = result.tableMap.get(table);
- if (info == null)
- result.tableMap.put(table, info = new TableInfo());
- info.onlineTablets++;
- info.recs = info.onlineTablets;
- info.ingestRate = 123.;
- info.queryRate = 456.;
- }
- return result;
- }
- }
-
- Map<TServerInstance,FakeTServer> servers = new HashMap<TServerInstance,FakeTServer>();
-
- class TestDefaultLoadBalancer extends DefaultLoadBalancer {
-
- @Override
- public List<TabletStats> getOnlineTabletsForTable(TServerInstance tserver, String table) throws ThriftSecurityException, TException {
- List<TabletStats> result = new ArrayList<TabletStats>();
- for (KeyExtent extent : servers.get(tserver).extents) {
- if (extent.getTableId().toString().equals(table)) {
- result.add(new TabletStats(extent.toThrift(), null, null, null, 0l, 0., 0., 0));
- }
- }
- return result;
- }
- }
-
- @Test
- public void testAssignMigrations() {
- servers.clear();
- servers.put(new TServerInstance(AddressUtil.parseAddress("127.0.0.1", 1234), "a"), new FakeTServer());
- servers.put(new TServerInstance(AddressUtil.parseAddress("127.0.0.1", 1235), "b"), new FakeTServer());
- servers.put(new TServerInstance(AddressUtil.parseAddress("127.0.0.1", 1236), "c"), new FakeTServer());
- List<KeyExtent> metadataTable = new ArrayList<KeyExtent>();
- String table = "t1";
- metadataTable.add(makeExtent(table, null, null));
- table = "t2";
- metadataTable.add(makeExtent(table, "a", null));
- metadataTable.add(makeExtent(table, null, "a"));
- table = "t3";
- metadataTable.add(makeExtent(table, "a", null));
- metadataTable.add(makeExtent(table, "b", "a"));
- metadataTable.add(makeExtent(table, "c", "b"));
- metadataTable.add(makeExtent(table, "d", "c"));
- metadataTable.add(makeExtent(table, "e", "d"));
- metadataTable.add(makeExtent(table, null, "e"));
- Collections.sort(metadataTable);
-
- TestDefaultLoadBalancer balancer = new TestDefaultLoadBalancer();
-
- SortedMap<TServerInstance,TabletServerStatus> current = new TreeMap<TServerInstance,TabletServerStatus>();
- for (Entry<TServerInstance,FakeTServer> entry : servers.entrySet()) {
- current.put(entry.getKey(), entry.getValue().getStatus(entry.getKey()));
- }
- assignTablets(metadataTable, servers, current, balancer);
-
- // Verify that the counts on the tables are correct
- Map<String,Integer> expectedCounts = new HashMap<String,Integer>();
- expectedCounts.put("t1", 1);
- expectedCounts.put("t2", 1);
- expectedCounts.put("t3", 2);
- checkBalance(metadataTable, servers, expectedCounts);
-
- // Rebalance once
- for (Entry<TServerInstance,FakeTServer> entry : servers.entrySet()) {
- current.put(entry.getKey(), entry.getValue().getStatus(entry.getKey()));
- }
-
- // Nothing should happen, we are balanced
- ArrayList<TabletMigration> out = new ArrayList<TabletMigration>();
- balancer.getMigrations(current, out);
- assertEquals(out.size(), 0);
-
- // Take down a tabletServer
- TServerInstance first = current.keySet().iterator().next();
- current.remove(first);
- FakeTServer remove = servers.remove(first);
-
- // reassign offline extents
- assignTablets(remove.extents, servers, current, balancer);
- checkBalance(metadataTable, servers, null);
- }
-
- private void assignTablets(List<KeyExtent> metadataTable, Map<TServerInstance,FakeTServer> servers, SortedMap<TServerInstance,TabletServerStatus> status,
- TestDefaultLoadBalancer balancer) {
- // Assign tablets
- for (KeyExtent extent : metadataTable) {
- TServerInstance assignment = balancer.getAssignment(status, extent, null);
- assertNotNull(assignment);
- assertFalse(servers.get(assignment).extents.contains(extent));
- servers.get(assignment).extents.add(extent);
- }
- }
-
- SortedMap<TServerInstance,TabletServerStatus> getAssignments(Map<TServerInstance,FakeTServer> servers) {
- SortedMap<TServerInstance,TabletServerStatus> result = new TreeMap<TServerInstance,TabletServerStatus>();
- for (Entry<TServerInstance,FakeTServer> entry : servers.entrySet()) {
- result.put(entry.getKey(), entry.getValue().getStatus(entry.getKey()));
- }
- return result;
- }
-
- @Test
- public void testUnevenAssignment() {
- servers.clear();
- for (char c : "abcdefghijklmnopqrstuvwxyz".toCharArray()) {
- String cString = Character.toString(c);
- InetSocketAddress fakeAddress = AddressUtil.parseAddress("127.0.0.1", (int) c);
- String fakeInstance = cString;
- TServerInstance tsi = new TServerInstance(fakeAddress, fakeInstance);
- FakeTServer fakeTServer = new FakeTServer();
- servers.put(tsi, fakeTServer);
- fakeTServer.extents.add(makeExtent(cString, null, null));
- }
- // Put more tablets on one server, but not more than the number of servers
- Entry<TServerInstance,FakeTServer> first = servers.entrySet().iterator().next();
- first.getValue().extents.add(makeExtent("newTable", "a", null));
- first.getValue().extents.add(makeExtent("newTable", "b", "a"));
- first.getValue().extents.add(makeExtent("newTable", "c", "b"));
- first.getValue().extents.add(makeExtent("newTable", "d", "c"));
- first.getValue().extents.add(makeExtent("newTable", "e", "d"));
- first.getValue().extents.add(makeExtent("newTable", "f", "e"));
- first.getValue().extents.add(makeExtent("newTable", "g", "f"));
- first.getValue().extents.add(makeExtent("newTable", "h", "g"));
- first.getValue().extents.add(makeExtent("newTable", "i", null));
- TestDefaultLoadBalancer balancer = new TestDefaultLoadBalancer();
- Set<KeyExtent> migrations = Collections.emptySet();
- int moved = 0;
- // balance until we can't balance no more!
- while (true) {
- List<TabletMigration> migrationsOut = new ArrayList<TabletMigration>();
- balancer.balance(getAssignments(servers), migrations, migrationsOut);
- if (migrationsOut.size() == 0)
- break;
- for (TabletMigration migration : migrationsOut) {
- if (servers.get(migration.oldServer).extents.remove(migration.tablet))
- moved++;
- servers.get(migration.newServer).extents.add(migration.tablet);
- }
- }
- assertEquals(8, moved);
- }
-
- @Test
- public void testUnevenAssignment2() {
- servers.clear();
- // make 26 servers
- for (char c : "abcdefghijklmnopqrstuvwxyz".toCharArray()) {
- String cString = Character.toString(c);
- InetSocketAddress fakeAddress = AddressUtil.parseAddress("127.0.0.1", (int) c);
- String fakeInstance = cString;
- TServerInstance tsi = new TServerInstance(fakeAddress, fakeInstance);
- FakeTServer fakeTServer = new FakeTServer();
- servers.put(tsi, fakeTServer);
- }
- // put 60 tablets on 25 of them
- List<Entry<TServerInstance,FakeTServer>> shortList = new ArrayList<Entry<TServerInstance,FakeTServer>>(servers.entrySet());
- Entry<TServerInstance,FakeTServer> shortServer = shortList.remove(0);
- int c = 0;
- for (int i = 0; i < 60; i++) {
- for (Entry<TServerInstance,FakeTServer> entry : shortList) {
- entry.getValue().extents.add(makeExtent("t" + c, null, null));
- }
- }
- // put 10 on the that short server:
- for (int i = 0; i < 10; i++) {
- shortServer.getValue().extents.add(makeExtent("s" + i, null, null));
- }
-
- TestDefaultLoadBalancer balancer = new TestDefaultLoadBalancer();
- Set<KeyExtent> migrations = Collections.emptySet();
- int moved = 0;
- // balance until we can't balance no more!
- while (true) {
- List<TabletMigration> migrationsOut = new ArrayList<TabletMigration>();
- balancer.balance(getAssignments(servers), migrations, migrationsOut);
- if (migrationsOut.size() == 0)
- break;
- for (TabletMigration migration : migrationsOut) {
- if (servers.get(migration.oldServer).extents.remove(migration.tablet))
- moved++;
- servers.get(migration.newServer).extents.add(migration.tablet);
- }
- }
- // average is 58, with 2 at 59: we need 48 more moved to the short server
- assertEquals(48, moved);
- }
-
- private void checkBalance(List<KeyExtent> metadataTable, Map<TServerInstance,FakeTServer> servers, Map<String,Integer> expectedCounts) {
- // Verify they are spread evenly over the cluster
- int average = metadataTable.size() / servers.size();
- for (FakeTServer server : servers.values()) {
- int diff = server.extents.size() - average;
- if (diff < 0)
- fail("average number of tablets is " + average + " but a server has " + server.extents.size());
- if (diff > 1)
- fail("average number of tablets is " + average + " but a server has " + server.extents.size());
- }
-
- if (expectedCounts != null) {
- for (FakeTServer server : servers.values()) {
- Map<String,Integer> counts = new HashMap<String,Integer>();
- for (KeyExtent extent : server.extents) {
- String t = extent.getTableId().toString();
- if (counts.get(t) == null)
- counts.put(t, 0);
- counts.put(t, counts.get(t) + 1);
- }
- for (Entry<String,Integer> entry : counts.entrySet()) {
- assertEquals(expectedCounts.get(entry.getKey()), counts.get(entry.getKey()));
- }
- }
- }
- }
-
- private static KeyExtent makeExtent(String table, String end, String prev) {
- return new KeyExtent(new Text(table), toText(end), toText(prev));
- }
-
- private static Text toText(String value) {
- if (value != null)
- return new Text(value);
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/88079cc3/server/server/src/test/java/org/apache/accumulo/server/master/balancer/TableLoadBalancerTest.java
----------------------------------------------------------------------
diff --git a/server/server/src/test/java/org/apache/accumulo/server/master/balancer/TableLoadBalancerTest.java b/server/server/src/test/java/org/apache/accumulo/server/master/balancer/TableLoadBalancerTest.java
deleted file mode 100644
index 71ba50d..0000000
--- a/server/server/src/test/java/org/apache/accumulo/server/master/balancer/TableLoadBalancerTest.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * 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 org.apache.accumulo.server.master.balancer;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
-import org.apache.accumulo.core.client.Connector;
-import org.apache.accumulo.core.client.admin.TableOperations;
-import org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException;
-import org.apache.accumulo.core.client.mock.MockInstance;
-import org.apache.accumulo.core.client.security.tokens.PasswordToken;
-import org.apache.accumulo.core.data.KeyExtent;
-import org.apache.accumulo.core.master.thrift.TableInfo;
-import org.apache.accumulo.core.master.thrift.TabletServerStatus;
-import org.apache.accumulo.core.tabletserver.thrift.TabletStats;
-import org.apache.accumulo.core.util.AddressUtil;
-import org.apache.accumulo.server.master.state.TServerInstance;
-import org.apache.accumulo.server.master.state.TabletMigration;
-import org.apache.hadoop.io.Text;
-import org.apache.thrift.TException;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class TableLoadBalancerTest {
-
- static private TServerInstance mkts(String address, String session) throws Exception {
- return new TServerInstance(AddressUtil.parseAddress(address, 1234), session);
- }
-
- static private TabletServerStatus status(Object... config) {
- TabletServerStatus result = new TabletServerStatus();
- result.tableMap = new HashMap<String,TableInfo>();
- String tablename = null;
- for (Object c : config) {
- if (c instanceof String) {
- tablename = (String) c;
- } else {
- TableInfo info = new TableInfo();
- int count = (Integer) c;
- info.onlineTablets = count;
- info.tablets = count;
- result.tableMap.put(tablename, info);
- }
- }
- return result;
- }
-
- static MockInstance instance = new MockInstance("mockamatic");
-
- static SortedMap<TServerInstance,TabletServerStatus> state;
-
- static List<TabletStats> generateFakeTablets(TServerInstance tserver, String tableId) {
- List<TabletStats> result = new ArrayList<TabletStats>();
- TabletServerStatus tableInfo = state.get(tserver);
- // generate some fake tablets
- for (int i = 0; i < tableInfo.tableMap.get(tableId).onlineTablets; i++) {
- TabletStats stats = new TabletStats();
- stats.extent = new KeyExtent(new Text(tableId), new Text(tserver.host() + String.format("%03d", i + 1)), new Text(tserver.host()
- + String.format("%03d", i))).toThrift();
- result.add(stats);
- }
- return result;
- }
-
- static class DefaultLoadBalancer extends org.apache.accumulo.server.master.balancer.DefaultLoadBalancer {
-
- public DefaultLoadBalancer(String table) {
- super(table);
- }
-
- @Override
- public List<TabletStats> getOnlineTabletsForTable(TServerInstance tserver, String tableId) throws ThriftSecurityException, TException {
- return generateFakeTablets(tserver, tableId);
- }
- }
-
- // ugh... so wish I had provided mock objects to the LoadBalancer in the master
- static class TableLoadBalancer extends org.apache.accumulo.server.master.balancer.TableLoadBalancer {
-
- TableLoadBalancer() {
- super();
- }
-
- // need to use our mock instance
- @Override
- protected TableOperations getTableOperations() {
- try {
- return instance.getConnector("user", new PasswordToken("pass")).tableOperations();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- // use our new classname to test class loading
- @Override
- protected String getLoadBalancerClassNameForTable(String table) {
- return DefaultLoadBalancer.class.getName();
- }
-
- // we don't have real tablet servers to ask: invent some online tablets
- @Override
- public List<TabletStats> getOnlineTabletsForTable(TServerInstance tserver, String tableId) throws ThriftSecurityException, TException {
- return generateFakeTablets(tserver, tableId);
- }
- }
-
- @Test
- public void test() throws Exception {
- Connector c = instance.getConnector("user", new PasswordToken("pass"));
- c.tableOperations().create("t1");
- c.tableOperations().create("t2");
- c.tableOperations().create("t3");
- state = new TreeMap<TServerInstance,TabletServerStatus>();
- TServerInstance svr = mkts("10.0.0.1:1234", "0x01020304");
- state.put(svr, status("t1", 10, "t2", 10, "t3", 10));
-
- Set<KeyExtent> migrations = Collections.emptySet();
- List<TabletMigration> migrationsOut = new ArrayList<TabletMigration>();
- TableLoadBalancer tls = new TableLoadBalancer();
- tls.balance(state, migrations, migrationsOut);
- Assert.assertEquals(0, migrationsOut.size());
-
- state.put(mkts("10.0.0.2:1234", "0x02030405"), status());
- tls = new TableLoadBalancer();
- tls.balance(state, migrations, migrationsOut);
- int count = 0;
- Map<String,Integer> movedByTable = new HashMap<String,Integer>();
- movedByTable.put("t1", new Integer(0));
- movedByTable.put("t2", new Integer(0));
- movedByTable.put("t3", new Integer(0));
- for (TabletMigration migration : migrationsOut) {
- if (migration.oldServer.equals(svr))
- count++;
- String key = migration.tablet.getTableId().toString();
- movedByTable.put(key, movedByTable.get(key) + 1);
- }
- Assert.assertEquals(15, count);
- for (Integer moved : movedByTable.values()) {
- Assert.assertEquals(5, moved.intValue());
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/88079cc3/server/server/src/test/java/org/apache/accumulo/server/master/state/MergeInfoTest.java
----------------------------------------------------------------------
diff --git a/server/server/src/test/java/org/apache/accumulo/server/master/state/MergeInfoTest.java b/server/server/src/test/java/org/apache/accumulo/server/master/state/MergeInfoTest.java
deleted file mode 100644
index e1e2dd5..0000000
--- a/server/server/src/test/java/org/apache/accumulo/server/master/state/MergeInfoTest.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * 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 org.apache.accumulo.server.master.state;
-
-import org.apache.accumulo.core.data.KeyExtent;
-import org.apache.accumulo.server.master.state.MergeInfo;
-import org.apache.accumulo.server.master.state.MergeState;
-import org.apache.hadoop.io.DataInputBuffer;
-import org.apache.hadoop.io.DataOutputBuffer;
-import org.apache.hadoop.io.Text;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class MergeInfoTest {
-
- MergeInfo readWrite(MergeInfo info) throws Exception {
- DataOutputBuffer buffer = new DataOutputBuffer();
- info.write(buffer);
- DataInputBuffer in = new DataInputBuffer();
- in.reset(buffer.getData(), 0, buffer.getLength());
- MergeInfo info2 = new MergeInfo();
- info2.readFields(in);
- Assert.assertEquals(info.extent, info2.extent);
- Assert.assertEquals(info.state, info2.state);
- Assert.assertEquals(info.operation, info2.operation);
- return info2;
- }
-
- KeyExtent ke(String tableId, String endRow, String prevEndRow) {
- return new KeyExtent(new Text(tableId), endRow == null ? null : new Text(endRow), prevEndRow == null ? null : new Text(prevEndRow));
- }
-
- @Test
- public void testWritable() throws Exception {
- MergeInfo info;
- info = readWrite(new MergeInfo(ke("a", null, "b"), MergeInfo.Operation.MERGE));
- info = readWrite(new MergeInfo(ke("a", "b", null), MergeInfo.Operation.MERGE));
- info = readWrite(new MergeInfo(ke("x", "b", "a"), MergeInfo.Operation.MERGE));
- info = readWrite(new MergeInfo(ke("x", "b", "a"), MergeInfo.Operation.DELETE));
- Assert.assertTrue(info.isDelete());
- info.setState(MergeState.COMPLETE);
- }
-
- @Test
- public void testNeedsToBeChopped() throws Exception {
- MergeInfo info = new MergeInfo(ke("x", "b", "a"), MergeInfo.Operation.DELETE);
- Assert.assertTrue(info.needsToBeChopped(ke("x", "c", "b")));
- Assert.assertTrue(info.overlaps(ke("x", "c", "b")));
- Assert.assertFalse(info.needsToBeChopped(ke("y", "c", "b")));
- Assert.assertFalse(info.needsToBeChopped(ke("x", "c", "bb")));
- Assert.assertFalse(info.needsToBeChopped(ke("x", "b", "a")));
- info = new MergeInfo(ke("x", "b", "a"), MergeInfo.Operation.MERGE);
- Assert.assertTrue(info.needsToBeChopped(ke("x", "c", "a")));
- Assert.assertTrue(info.needsToBeChopped(ke("x", "aa", "a")));
- Assert.assertTrue(info.needsToBeChopped(ke("x", null, null)));
- Assert.assertFalse(info.needsToBeChopped(ke("x", "c", "b")));
- Assert.assertFalse(info.needsToBeChopped(ke("y", "c", "b")));
- Assert.assertFalse(info.needsToBeChopped(ke("x", "c", "bb")));
- Assert.assertTrue(info.needsToBeChopped(ke("x", "b", "a")));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/88079cc3/server/server/src/test/java/org/apache/accumulo/server/master/state/RootTabletStateStoreTest.java
----------------------------------------------------------------------
diff --git a/server/server/src/test/java/org/apache/accumulo/server/master/state/RootTabletStateStoreTest.java b/server/server/src/test/java/org/apache/accumulo/server/master/state/RootTabletStateStoreTest.java
deleted file mode 100644
index a5613ea..0000000
--- a/server/server/src/test/java/org/apache/accumulo/server/master/state/RootTabletStateStoreTest.java
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- * 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 org.apache.accumulo.server.master.state;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-
-import org.apache.accumulo.core.data.KeyExtent;
-import org.apache.accumulo.core.metadata.RootTable;
-import org.apache.accumulo.core.util.AddressUtil;
-import org.apache.accumulo.server.master.state.TabletLocationState.BadLocationStateException;
-import org.apache.hadoop.io.Text;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class RootTabletStateStoreTest {
-
- static class Node {
- Node(String name) {
- this.name = name;
- }
-
- List<Node> children = new ArrayList<Node>();
- String name;
- byte[] value = new byte[] {};
-
- Node find(String name) {
- for (Node node : children)
- if (node.name.equals(name))
- return node;
- return null;
- }
- };
-
- static class FakeZooStore implements DistributedStore {
-
- Node root = new Node("/");
-
- private Node recurse(Node root, String[] path, int depth) {
- if (depth == path.length)
- return root;
- Node child = root.find(path[depth]);
- if (child == null)
- return null;
- return recurse(child, path, depth + 1);
- }
-
- private Node navigate(String path) {
- path = path.replaceAll("/$", "");
- return recurse(root, path.split("/"), 1);
- }
-
- @Override
- public List<String> getChildren(String path) throws DistributedStoreException {
- Node node = navigate(path);
- if (node == null)
- return Collections.emptyList();
- List<String> children = new ArrayList<String>(node.children.size());
- for (Node child : node.children)
- children.add(child.name);
- return children;
- }
-
- @Override
- public void put(String path, byte[] bs) throws DistributedStoreException {
- create(path).value = bs;
- }
-
- private Node create(String path) {
- String[] parts = path.split("/");
- return recurseCreate(root, parts, 1);
- }
-
- private Node recurseCreate(Node root, String[] path, int index) {
- if (path.length == index)
- return root;
- Node node = root.find(path[index]);
- if (node == null) {
- node = new Node(path[index]);
- root.children.add(node);
- }
- return recurseCreate(node, path, index + 1);
- }
-
- @Override
- public void remove(String path) throws DistributedStoreException {
- String[] parts = path.split("/");
- String[] parentPath = Arrays.copyOf(parts, parts.length - 1);
- Node parent = recurse(root, parentPath, 1);
- if (parent == null)
- return;
- Node child = parent.find(parts[parts.length - 1]);
- if (child != null)
- parent.children.remove(child);
- }
-
- @Override
- public byte[] get(String path) throws DistributedStoreException {
- Node node = navigate(path);
- if (node != null)
- return node.value;
- return null;
- }
- }
-
- @Test
- public void testFakeZoo() throws DistributedStoreException {
- DistributedStore store = new FakeZooStore();
- store.put("/a/b/c", "abc".getBytes());
- byte[] abc = store.get("/a/b/c");
- assertArrayEquals(abc, "abc".getBytes());
- byte[] empty = store.get("/a/b");
- assertArrayEquals(empty, "".getBytes());
- store.put("/a/b", "ab".getBytes());
- assertArrayEquals(store.get("/a/b"), "ab".getBytes());
- store.put("/a/b/b", "abb".getBytes());
- List<String> children = store.getChildren("/a/b");
- assertEquals(new HashSet<String>(children), new HashSet<String>(Arrays.asList("b", "c")));
- store.remove("/a/b/c");
- children = store.getChildren("/a/b");
- assertEquals(new HashSet<String>(children), new HashSet<String>(Arrays.asList("b")));
- }
-
- @Test
- public void testRootTabletStateStore() throws DistributedStoreException {
- ZooTabletStateStore tstore = new ZooTabletStateStore(new FakeZooStore());
- KeyExtent root = RootTable.EXTENT;
- String sessionId = "this is my unique session data";
- TServerInstance server = new TServerInstance(AddressUtil.parseAddress("127.0.0.1", 10000), sessionId);
- List<Assignment> assignments = Collections.singletonList(new Assignment(root, server));
- tstore.setFutureLocations(assignments);
- int count = 0;
- for (TabletLocationState location : tstore) {
- assertEquals(location.extent, root);
- assertEquals(location.future, server);
- assertNull(location.current);
- count++;
- }
- assertEquals(count, 1);
- tstore.setLocations(assignments);
- count = 0;
- for (TabletLocationState location : tstore) {
- assertEquals(location.extent, root);
- assertNull(location.future);
- assertEquals(location.current, server);
- count++;
- }
- assertEquals(count, 1);
- TabletLocationState assigned = null;
- try {
- assigned = new TabletLocationState(root, server, null, null, null, false);
- } catch (BadLocationStateException e) {
- fail("Unexpected error " + e);
- }
- tstore.unassign(Collections.singletonList(assigned));
- count = 0;
- for (TabletLocationState location : tstore) {
- assertEquals(location.extent, root);
- assertNull(location.future);
- assertNull(location.current);
- count++;
- }
- assertEquals(count, 1);
-
- KeyExtent notRoot = new KeyExtent(new Text("0"), null, null);
- try {
- tstore.setLocations(Collections.singletonList(new Assignment(notRoot, server)));
- Assert.fail("should not get here");
- } catch (IllegalArgumentException ex) {}
-
- try {
- tstore.setFutureLocations(Collections.singletonList(new Assignment(notRoot, server)));
- Assert.fail("should not get here");
- } catch (IllegalArgumentException ex) {}
-
- TabletLocationState broken = null;
- try {
- broken = new TabletLocationState(notRoot, server, null, null, null, false);
- } catch (BadLocationStateException e) {
- fail("Unexpected error " + e);
- }
- try {
- tstore.unassign(Collections.singletonList(broken));
- Assert.fail("should not get here");
- } catch (IllegalArgumentException ex) {}
- }
-
- // @Test
- // public void testMetaDataStore() { } // see functional test
-}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/88079cc3/server/server/src/test/java/org/apache/accumulo/server/tabletserver/CheckTabletMetadataTest.java
----------------------------------------------------------------------
diff --git a/server/server/src/test/java/org/apache/accumulo/server/tabletserver/CheckTabletMetadataTest.java b/server/server/src/test/java/org/apache/accumulo/server/tabletserver/CheckTabletMetadataTest.java
index 8fe1ea0..aa7e7a4 100644
--- a/server/server/src/test/java/org/apache/accumulo/server/tabletserver/CheckTabletMetadataTest.java
+++ b/server/server/src/test/java/org/apache/accumulo/server/tabletserver/CheckTabletMetadataTest.java
@@ -24,7 +24,7 @@ import org.apache.accumulo.core.data.KeyExtent;
import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection;
import org.apache.accumulo.core.util.ColumnFQ;
-import org.apache.accumulo.server.master.state.TServerInstance;
+import org.apache.accumulo.master.state.TServerInstance;
import org.apache.hadoop.io.Text;
import org.junit.Assert;
import org.junit.Test;