use of org.apache.accumulo.fate.zookeeper.IZooReaderWriter.Mutator in project accumulo by apache.
the class ZooReaderWriterTest method testMutateWithBadVersion.
@Test
public void testMutateWithBadVersion() throws Exception {
final String path = "/foo";
final byte[] value = new byte[] { 0 };
final List<ACL> acls = Collections.emptyList();
final byte[] mutatedBytes = new byte[] { 1 };
Mutator mutator = new Mutator() {
@Override
public byte[] mutate(byte[] currentValue) throws Exception {
return mutatedBytes;
}
};
Method getDataMethod = ZooReaderWriter.class.getMethod("getData", String.class, boolean.class, Stat.class);
zrw = EasyMock.createMockBuilder(ZooReaderWriter.class).addMockedMethods("getRetryFactory", "getZooKeeper").addMockedMethod(getDataMethod).createMock();
EasyMock.expect(zrw.getRetryFactory()).andReturn(retryFactory).anyTimes();
EasyMock.expect(zrw.getZooKeeper()).andReturn(zk).anyTimes();
Stat stat = new Stat();
zk.create(path, value, acls, CreateMode.PERSISTENT);
EasyMock.expectLastCall().andThrow(new NodeExistsException()).once();
EasyMock.expect(zrw.getData(path, false, stat)).andReturn(new byte[] { 3 }).times(2);
// BadVersionException should retry
EasyMock.expect(zk.setData(path, mutatedBytes, 0)).andThrow(new BadVersionException());
// Let 2nd setData succeed
EasyMock.expect(zk.setData(path, mutatedBytes, 0)).andReturn(null);
EasyMock.replay(zk, zrw, retryFactory, retry);
Assert.assertArrayEquals(new byte[] { 1 }, zrw.mutate(path, value, acls, mutator));
EasyMock.verify(zk, zrw, retryFactory, retry);
}
use of org.apache.accumulo.fate.zookeeper.IZooReaderWriter.Mutator in project accumulo by apache.
the class ZooReaderWriterTest method testMutateNodeCreationFails.
@Test(expected = SessionExpiredException.class)
public void testMutateNodeCreationFails() throws Exception {
final String path = "/foo";
final byte[] value = new byte[] { 0 };
final List<ACL> acls = Collections.emptyList();
Mutator mutator = new Mutator() {
@Override
public byte[] mutate(byte[] currentValue) throws Exception {
return new byte[] { 1 };
}
};
zk.create(path, value, acls, CreateMode.PERSISTENT);
EasyMock.expectLastCall().andThrow(new SessionExpiredException()).once();
EasyMock.expect(retry.canRetry()).andReturn(false);
EasyMock.expect(retry.retriesCompleted()).andReturn(1l).once();
EasyMock.replay(zk, zrw, retryFactory, retry);
zrw.mutate(path, value, acls, mutator);
}
use of org.apache.accumulo.fate.zookeeper.IZooReaderWriter.Mutator in project accumulo by apache.
the class RenameNamespace method call.
@Override
public Repo<Master> call(long id, Master master) throws Exception {
Instance instance = master.getInstance();
IZooReaderWriter zoo = ZooReaderWriter.getInstance();
Utils.tableNameLock.lock();
try {
Utils.checkNamespaceDoesNotExist(instance, newName, namespaceId, TableOperation.RENAME);
final String tap = ZooUtil.getRoot(instance) + Constants.ZNAMESPACES + "/" + namespaceId + Constants.ZNAMESPACE_NAME;
zoo.mutate(tap, null, null, new Mutator() {
@Override
public byte[] mutate(byte[] current) throws Exception {
final String currentName = new String(current);
if (currentName.equals(newName))
// assume in this case the operation is running again, so we are done
return null;
if (!currentName.equals(oldName)) {
throw new AcceptableThriftTableOperationException(null, oldName, TableOperation.RENAME, TableOperationExceptionType.NAMESPACE_NOTFOUND, "Name changed while processing");
}
return newName.getBytes();
}
});
Tables.clearCache(instance);
} finally {
Utils.tableNameLock.unlock();
Utils.unreserveNamespace(namespaceId, id, true);
}
LoggerFactory.getLogger(RenameNamespace.class).debug("Renamed namespace {} {} {}", namespaceId, oldName, newName);
return null;
}
use of org.apache.accumulo.fate.zookeeper.IZooReaderWriter.Mutator in project accumulo by apache.
the class CompactRange method call.
@Override
public Repo<Master> call(final long tid, Master env) throws Exception {
String zTablePath = Constants.ZROOT + "/" + env.getInstance().getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_COMPACT_ID;
IZooReaderWriter zoo = ZooReaderWriter.getInstance();
byte[] cid;
try {
cid = zoo.mutate(zTablePath, null, null, new Mutator() {
@Override
public byte[] mutate(byte[] currentValue) throws Exception {
String cvs = new String(currentValue, UTF_8);
String[] tokens = cvs.split(",");
long flushID = Long.parseLong(tokens[0]);
flushID++;
String txidString = String.format("%016x", tid);
for (int i = 1; i < tokens.length; i++) {
if (tokens[i].startsWith(txidString))
// skip self
continue;
log.debug("txidString : {}", txidString);
log.debug("tokens[{}] : {}", i, tokens[i]);
throw new AcceptableThriftTableOperationException(tableId.canonicalID(), null, TableOperation.COMPACT, TableOperationExceptionType.OTHER, "Another compaction with iterators and/or a compaction strategy is running");
}
StringBuilder encodedIterators = new StringBuilder();
if (config != null) {
Hex hex = new Hex();
encodedIterators.append(",");
encodedIterators.append(txidString);
encodedIterators.append("=");
encodedIterators.append(new String(hex.encode(config), UTF_8));
}
return (Long.toString(flushID) + encodedIterators).getBytes(UTF_8);
}
});
return new CompactionDriver(Long.parseLong(new String(cid, UTF_8).split(",")[0]), namespaceId, tableId, startRow, endRow);
} catch (NoNodeException nne) {
throw new AcceptableThriftTableOperationException(tableId.canonicalID(), null, TableOperation.COMPACT, TableOperationExceptionType.NOTFOUND, null);
}
}
use of org.apache.accumulo.fate.zookeeper.IZooReaderWriter.Mutator in project accumulo by apache.
the class CompactRange method removeIterators.
static void removeIterators(Master environment, final long txid, Table.ID tableId) throws Exception {
String zTablePath = Constants.ZROOT + "/" + environment.getInstance().getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_COMPACT_ID;
IZooReaderWriter zoo = ZooReaderWriter.getInstance();
zoo.mutate(zTablePath, null, null, new Mutator() {
@Override
public byte[] mutate(byte[] currentValue) throws Exception {
String cvs = new String(currentValue, UTF_8);
String[] tokens = cvs.split(",");
long flushID = Long.parseLong(tokens[0]);
String txidString = String.format("%016x", txid);
StringBuilder encodedIterators = new StringBuilder();
for (int i = 1; i < tokens.length; i++) {
if (tokens[i].startsWith(txidString))
continue;
encodedIterators.append(",");
encodedIterators.append(tokens[i]);
}
return (Long.toString(flushID) + encodedIterators).getBytes(UTF_8);
}
});
}
Aggregations