use of org.commonjava.indy.db.common.StoreUpdateAction.STORE in project indy by Commonjava.
the class AbstractStoreDataManager method store.
protected boolean store(final ArtifactStore store, final ChangeSummary summary, final boolean skipIfExists, final boolean fireEvents, final EventMetadata eventMetadata) throws IndyDataException {
if (store == null) {
logger.warn("Tried to store null ArtifactStore!");
return false;
}
AtomicReference<IndyDataException> error = new AtomicReference<>();
logger.trace("Storing {} using operation lock: {}", store, opLocks);
final StoreKey storeKey = store.getKey();
logger.warn("Storing {} using operation lock: {}", store, opLocks);
if (internalFeatureConfig != null && internalFeatureConfig.getStoreValidation() && store.getType() != group) {
ArtifactStoreValidateData validateData = storeValidator.validate(store);
if (!validateData.isValid()) {
logger.warn("=> [AbstractStoreDataManager] Adding Validation Metadata to Remote Store: " + store.getKey() + " - not Valid! ");
if (store.getMetadata() != null) {
store.getMetadata().putAll(validateData.getErrors());
} else {
store.setMetadata(validateData.getErrors());
}
}
}
Function<StoreKey, Boolean> lockHandler = k -> doStore(k, store, summary, error, skipIfExists, fireEvents, eventMetadata);
BiFunction<StoreKey, ReentrantLock, Boolean> lockFailedHandler = (k, lock) -> {
error.set(new IndyDataException("Failed to lock: %s for STORE after %d seconds.", k, LOCK_TIMEOUT_SECONDS));
return false;
};
Boolean result = opLocks.lockAnd(storeKey, LOCK_TIMEOUT_SECONDS, lockHandler, lockFailedHandler);
if (result == null) {
throw new IndyDataException("Store failed due to tryLock timeout.");
}
IndyDataException ex = error.get();
if (ex != null) {
throw ex;
}
return result;
}
use of org.commonjava.indy.db.common.StoreUpdateAction.STORE in project indy by Commonjava.
the class AbstractStoreDataManager method refreshAffectedBy.
@Measure
protected void refreshAffectedBy(final ArtifactStore store, final ArtifactStore original, StoreUpdateAction action) {
if (store == null) {
return;
}
if (store instanceof Group && isExcludedGroup((Group) store)) {
logger.info("Skip affectedBy calculation of group: {}", store.getName());
return;
}
if (action == DELETE) {
if (store instanceof Group) {
Group grp = (Group) store;
new HashSet<>(grp.getConstituents()).forEach((key) -> removeAffectedBy(key, store.getKey()));
logger.info("Removed affected-by reverse mapping for: {} in {} member stores", store.getKey(), grp.getConstituents().size());
} else {
removeAffectedStore(store.getKey());
}
} else if (action == STORE) {
// NOTE: Only group membership changes can affect our affectedBy, unless the update is a store deletion.
if (store instanceof Group) {
final Set<StoreKey> updatedConstituents = new HashSet<>(((Group) store).getConstituents());
final Set<StoreKey> originalConstituents;
if (original != null) {
originalConstituents = new HashSet<>(((Group) original).getConstituents());
} else {
originalConstituents = new HashSet<>();
}
final Set<StoreKey> added = new HashSet<>();
final Set<StoreKey> removed = new HashSet<>();
for (StoreKey updKey : updatedConstituents) {
if (!originalConstituents.contains(updKey)) {
added.add(updKey);
}
}
for (StoreKey oriKey : originalConstituents) {
if (!updatedConstituents.contains(oriKey)) {
removed.add(oriKey);
}
}
removed.forEach((key) -> removeAffectedBy(key, store.getKey()));
logger.info("Removed affected-by reverse mapping for: {} in {} member stores", store.getKey(), removed.size());
added.forEach((key) -> addAffectedBy(key, store.getKey()));
logger.info("Added affected-by reverse mapping for: {} in {} member stores", store.getKey(), added.size());
}
}
}
Aggregations