use of org.apache.accumulo.fate.zookeeper.IZooReaderWriter in project accumulo by apache.
the class MasterClientServiceHandler method initiateFlush.
@Override
public long initiateFlush(TInfo tinfo, TCredentials c, String tableIdStr) throws ThriftSecurityException, ThriftTableOperationException {
Table.ID tableId = Table.ID.of(tableIdStr);
Namespace.ID namespaceId = getNamespaceIdFromTableId(TableOperation.FLUSH, tableId);
master.security.canFlush(c, tableId, namespaceId);
String zTablePath = Constants.ZROOT + "/" + master.getInstance().getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_FLUSH_ID;
IZooReaderWriter zoo = ZooReaderWriter.getInstance();
byte[] fid;
try {
fid = zoo.mutate(zTablePath, null, null, new Mutator() {
@Override
public byte[] mutate(byte[] currentValue) throws Exception {
long flushID = Long.parseLong(new String(currentValue));
flushID++;
return ("" + flushID).getBytes();
}
});
} catch (NoNodeException nne) {
throw new ThriftTableOperationException(tableId.canonicalID(), null, TableOperation.FLUSH, TableOperationExceptionType.NOTFOUND, null);
} catch (Exception e) {
Master.log.warn("{}", e.getMessage(), e);
throw new ThriftTableOperationException(tableId.canonicalID(), null, TableOperation.FLUSH, TableOperationExceptionType.OTHER, null);
}
return Long.parseLong(new String(fid));
}
use of org.apache.accumulo.fate.zookeeper.IZooReaderWriter in project accumulo by apache.
the class CancelCompactions method call.
@Override
public Repo<Master> call(long tid, Master environment) throws Exception {
String zCompactID = Constants.ZROOT + "/" + environment.getInstance().getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_COMPACT_ID;
String zCancelID = Constants.ZROOT + "/" + environment.getInstance().getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_COMPACT_CANCEL_ID;
IZooReaderWriter zoo = ZooReaderWriter.getInstance();
byte[] currentValue = zoo.getData(zCompactID, null);
String cvs = new String(currentValue, UTF_8);
String[] tokens = cvs.split(",");
final long flushID = Long.parseLong(tokens[0]);
zoo.mutate(zCancelID, null, null, new Mutator() {
@Override
public byte[] mutate(byte[] currentValue) throws Exception {
long cid = Long.parseLong(new String(currentValue, UTF_8));
if (cid < flushID)
return Long.toString(flushID).getBytes(UTF_8);
else
return Long.toString(cid).getBytes(UTF_8);
}
});
return new FinishCancelCompaction(namespaceId, tableId);
}
use of org.apache.accumulo.fate.zookeeper.IZooReaderWriter in project accumulo by apache.
the class DatafileManager method bringMajorCompactionOnline.
void bringMajorCompactionOnline(Set<FileRef> oldDatafiles, FileRef tmpDatafile, FileRef newDatafile, Long compactionId, DataFileValue dfv) throws IOException {
final KeyExtent extent = tablet.getExtent();
long t1, t2;
if (!extent.isRootTablet()) {
if (tablet.getTabletServer().getFileSystem().exists(newDatafile.path())) {
log.error("Target map file already exist " + newDatafile, new Exception());
throw new IllegalStateException("Target map file already exist " + newDatafile);
}
// rename before putting in metadata table, so files in metadata table should
// always exist
rename(tablet.getTabletServer().getFileSystem(), tmpDatafile.path(), newDatafile.path());
if (dfv.getNumEntries() == 0) {
tablet.getTabletServer().getFileSystem().deleteRecursively(newDatafile.path());
}
}
TServerInstance lastLocation = null;
synchronized (tablet) {
t1 = System.currentTimeMillis();
IZooReaderWriter zoo = ZooReaderWriter.getInstance();
tablet.incrementDataSourceDeletions();
if (extent.isRootTablet()) {
waitForScansToFinish(oldDatafiles, true, Long.MAX_VALUE);
try {
if (!zoo.isLockHeld(tablet.getTabletServer().getLock().getLockID())) {
throw new IllegalStateException();
}
} catch (Exception e) {
throw new IllegalStateException("Can not bring major compaction online, lock not held", e);
}
// mark files as ready for deletion, but
// do not delete them until we successfully
// rename the compacted map file, in case
// the system goes down
RootFiles.replaceFiles(tablet.getTableConfiguration(), tablet.getTabletServer().getFileSystem(), tablet.getLocation(), oldDatafiles, tmpDatafile, newDatafile);
}
// atomically remove old files and add new file
for (FileRef oldDatafile : oldDatafiles) {
if (!datafileSizes.containsKey(oldDatafile)) {
log.error("file does not exist in set {}", oldDatafile);
}
datafileSizes.remove(oldDatafile);
majorCompactingFiles.remove(oldDatafile);
}
if (datafileSizes.containsKey(newDatafile)) {
log.error("Adding file that is already in set {}", newDatafile);
}
if (dfv.getNumEntries() > 0) {
datafileSizes.put(newDatafile, dfv);
}
// could be used by a follow on compaction in a multipass compaction
majorCompactingFiles.add(newDatafile);
tablet.computeNumEntries();
lastLocation = tablet.resetLastLocation();
tablet.setLastCompactionID(compactionId);
t2 = System.currentTimeMillis();
}
if (!extent.isRootTablet()) {
Set<FileRef> filesInUseByScans = waitForScansToFinish(oldDatafiles, false, 10000);
if (filesInUseByScans.size() > 0)
log.debug("Adding scan refs to metadata {} {}", extent, filesInUseByScans);
MasterMetadataUtil.replaceDatafiles(tablet.getTabletServer(), extent, oldDatafiles, filesInUseByScans, newDatafile, compactionId, dfv, tablet.getTabletServer().getClientAddressString(), lastLocation, tablet.getTabletServer().getLock());
removeFilesAfterScan(filesInUseByScans);
}
log.debug(String.format("MajC finish lock %.2f secs", (t2 - t1) / 1000.0));
log.debug("TABLET_HIST {} MajC --> {}", oldDatafiles, newDatafile);
}
use of org.apache.accumulo.fate.zookeeper.IZooReaderWriter in project accumulo by apache.
the class FunctionalTestUtils method getFateStatus.
private static FateStatus getFateStatus(Instance instance, AccumuloCluster cluster) {
try {
AdminUtil<String> admin = new AdminUtil<>(false);
String secret = cluster.getSiteConfiguration().get(Property.INSTANCE_SECRET);
IZooReaderWriter zk = new ZooReaderWriterFactory().getZooReaderWriter(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut(), secret);
ZooStore<String> zs = new ZooStore<>(ZooUtil.getRoot(instance) + Constants.ZFATE, zk);
FateStatus fateStatus = admin.getStatus(zs, zk, ZooUtil.getRoot(instance) + Constants.ZTABLE_LOCKS, null, null);
return fateStatus;
} catch (KeeperException | InterruptedException e) {
throw new RuntimeException(e);
}
}
use of org.apache.accumulo.fate.zookeeper.IZooReaderWriter in project accumulo by apache.
the class CacheTestClean method main.
public static void main(String[] args) throws Exception {
String rootDir = args[0];
File reportDir = new File(args[1]);
IZooReaderWriter zoo = ZooReaderWriter.getInstance();
if (zoo.exists(rootDir)) {
zoo.recursiveDelete(rootDir, NodeMissingPolicy.FAIL);
}
FileUtils.deleteQuietly(reportDir);
if (!reportDir.mkdirs()) {
throw new IOException("Unable to (re-)create " + reportDir);
}
}
Aggregations