use of org.apache.drill.common.concurrent.AutoCloseableLock in project drill by apache.
the class FunctionRegistryHolder method addJars.
/**
* Adds jars to the function registry.
* If jar with the same name already exists, it and its functions will be removed.
* Then jar will be added to {@link #jars}
* and each function will be added using {@link #addFunctions(Map, List)}.
* Registry version is updated with passed version if all jars were added successfully.
* This is write operation, so one user at a time can call perform such action,
* others will wait till first user completes his action.
*
* @param newJars jars and list of their function holders, each contains function name, signature and holder
*/
public void addJars(Map<String, List<FunctionHolder>> newJars, long version) {
try (AutoCloseableLock lock = writeLock.open()) {
for (Map.Entry<String, List<FunctionHolder>> newJar : newJars.entrySet()) {
String jarName = newJar.getKey();
removeAllByJar(jarName);
Map<String, Queue<String>> jar = Maps.newConcurrentMap();
jars.put(jarName, jar);
addFunctions(jar, newJar.getValue());
}
this.version = version;
}
}
use of org.apache.drill.common.concurrent.AutoCloseableLock in project drill by apache.
the class IncomingBuffers method close.
@Override
public void close() throws Exception {
try (AutoCloseableLock lock = exclusiveCloseLock.open()) {
closed = true;
AutoCloseables.close(collectorMap.values());
}
}
use of org.apache.drill.common.concurrent.AutoCloseableLock in project drill by apache.
the class IncomingBuffers method batchArrived.
public boolean batchArrived(final IncomingDataBatch incomingBatch) throws FragmentSetupException, IOException {
// Otherwise we would leak memory.
try (AutoCloseableLock lock = sharedIncomingBatchLock.open()) {
if (closed) {
return false;
}
if (incomingBatch.getHeader().getIsLastBatch()) {
streamsRemaining.decrementAndGet();
}
final int sendMajorFragmentId = incomingBatch.getHeader().getSendingMajorFragmentId();
DataCollector collector = collectorMap.get(sendMajorFragmentId);
if (collector == null) {
throw new FragmentSetupException(String.format("We received a major fragment id that we were not expecting. The id was %d. %s", sendMajorFragmentId, Arrays.toString(collectorMap.values().toArray())));
}
synchronized (collector) {
final RawFragmentBatch newRawFragmentBatch = incomingBatch.newRawFragmentBatch(context.getAllocator());
boolean decrementedToZero = collector.batchArrived(incomingBatch.getHeader().getSendingMinorFragmentId(), newRawFragmentBatch);
newRawFragmentBatch.release();
// we should only return true if remaining required has been decremented and is currently equal to zero.
return decrementedToZero;
}
}
}
use of org.apache.drill.common.concurrent.AutoCloseableLock in project drill by apache.
the class LocalPersistentStore method put.
@Override
public void put(String key, V value, DataChangeVersion dataChangeVersion) {
try (AutoCloseableLock lock = writeLock.open()) {
if (dataChangeVersion != null && dataChangeVersion.getVersion() != version) {
throw new VersionMismatchException("Version mismatch detected", dataChangeVersion.getVersion());
}
try (OutputStream os = fs.create(makePath(key))) {
IOUtils.write(config.getSerializer().serialize(value), os);
version++;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
use of org.apache.drill.common.concurrent.AutoCloseableLock in project drill by apache.
the class LocalPersistentStore method delete.
@Override
public void delete(String key) {
try (AutoCloseableLock lock = writeLock.open()) {
try {
fs.delete(makePath(key), false);
version++;
} catch (IOException e) {
logger.error("Unable to delete data from storage.", e);
throw new RuntimeException(e);
}
}
}
Aggregations