use of io.prestosql.spi.filesystem.FileBasedLock in project hetu-core by openlookeng.
the class FileBasedSeedStoreOnYarn method remove.
@Override
public Set<Seed> remove(Collection<Seed> seeds) throws IOException {
LOG.debug("FileBasedOnYarnSeedStore::remove() invoked.");
Path lockPath = seedFileFolder.resolve(name);
checkArgument(!lockPath.toString().contains("../"), "Lock path must be absolute and at user workspace " + SecurePathWhiteList.getSecurePathWhiteList().toString());
checkArgument(SecurePathWhiteList.isSecurePath(lockPath.toString()), "Lock path must be at user workspace " + SecurePathWhiteList.getSecurePathWhiteList().toString());
Lock lock = new FileBasedLock(fs, lockPath);
try {
lock.lock();
Set<Seed> outputs = new HashSet<>();
if (fs.exists(seedFilePath)) {
String json = loadFromFile(seedFilePath);
List<FileBasedSeedOnYarn> existingSeeds = LIST_FILE_BASED_SEED_CODEC.fromJson(json);
Set<FileBasedSeedOnYarn> latestSeeds = new HashSet<>(existingSeeds);
latestSeeds.removeAll(seeds.stream().filter(s -> (s instanceof FileBasedSeedOnYarn)).map(s -> (FileBasedSeedOnYarn) s).collect(Collectors.toList()));
String output = LIST_FILE_BASED_SEED_CODEC.toJson(ImmutableList.copyOf(latestSeeds));
writeToFile(seedFilePath, output, true);
outputs.addAll(latestSeeds);
}
return outputs;
} catch (UncheckedIOException e) {
throw new IOException(e);
} finally {
lock.unlock();
}
}
use of io.prestosql.spi.filesystem.FileBasedLock in project hetu-core by openlookeng.
the class HetuFsMetastore method runTransaction.
public synchronized void runTransaction(HetuFsMetadataHandler<PrestoException> handler) {
try {
Lock transactionLock;
transactionLock = new FileBasedLock(client, Paths.get(metadataPath));
transactionLock.lock();
try {
handler.handle();
} finally {
transactionLock.unlock();
}
} catch (IOException e) {
throw new PrestoException(HETU_METASTORE_CODE, "Create transaction lock failed", e);
}
}
Aggregations