use of org.projectnessie.error.NessieNotFoundException in project nessie by projectnessie.
the class IdentifyContentsPerExecutor method handleLiveCommit.
private void handleLiveCommit(GCStateParamsPerTask gcStateParamsPerTask, LogResponse.LogEntry logEntry, Map<String, ContentBloomFilter> bloomFilterMap, MutableBoolean foundAllLiveCommitHeadsBeforeCutoffTime, Set<ContentKey> liveContentKeys) {
if (logEntry.getOperations() != null) {
boolean isExpired = !gcStateParamsPerTask.getLiveCommitPredicate().test(logEntry.getCommitMeta());
if (isExpired && liveContentKeys.isEmpty()) {
// as it is the first expired commit. Time travel is supported till this state.
try {
gcStateParamsPerTask.getApi().getEntries().refName(Detached.REF_NAME).hashOnRef(logEntry.getCommitMeta().getHash()).get().getEntries().forEach(entries -> liveContentKeys.add(entries.getName()));
} catch (NessieNotFoundException e) {
throw new RuntimeException(e);
}
}
logEntry.getOperations().stream().filter(operation -> operation instanceof Operation.Put).forEach(operation -> {
boolean addContent;
if (liveContentKeys.contains(operation.getKey())) {
// commit head of this key
addContent = true;
liveContentKeys.remove(operation.getKey());
if (liveContentKeys.isEmpty()) {
// found all the live commit heads before cutoff time.
foundAllLiveCommitHeadsBeforeCutoffTime.setTrue();
}
} else {
addContent = !isExpired;
}
if (addContent) {
Content content = ((Operation.Put) operation).getContent();
bloomFilterMap.computeIfAbsent(content.getId(), k -> new ContentBloomFilter(gcStateParamsPerTask.getBloomFilterSize(), gcParams.getBloomFilterFpp())).put(content);
}
});
}
}
use of org.projectnessie.error.NessieNotFoundException in project nessie by projectnessie.
the class IdentifyContentsPerExecutor method walkAllCommitsInReference.
private IdentifiedResult walkAllCommitsInReference(NessieApiV1 api, Reference reference, Map<String, ContentBloomFilter> liveContentsBloomFilterMap) {
IdentifiedResult result = new IdentifiedResult();
Instant commitProtectionTime = Instant.now().minus(gcParams.getCommitProtectionDuration());
try (Stream<LogResponse.LogEntry> commits = StreamingUtil.getCommitLogStream(api, builder -> builder.hashOnRef(reference.getHash()).refName(Detached.REF_NAME).fetch(FetchOption.ALL), OptionalInt.empty())) {
commits.forEach(logEntry -> {
// Hence, protect those commits using commitProtectionTime.
if (logEntry.getCommitMeta().getCommitTime().compareTo(commitProtectionTime) < 0) {
// this commit can be tested for expiry as it is unprotected.
handleCommitForExpiredContents(reference, logEntry, liveContentsBloomFilterMap, result);
}
});
} catch (NessieNotFoundException e) {
throw new RuntimeException(e);
}
return result;
}
use of org.projectnessie.error.NessieNotFoundException in project nessie by projectnessie.
the class AbstractRestGC method fillExpectedContents.
void fillExpectedContents(Branch branch, int numCommits, IdentifiedResult expected) throws NessieNotFoundException {
fetchLogEntries(branch, numCommits).stream().map(LogEntry::getOperations).filter(Objects::nonNull).flatMap(Collection::stream).filter(op -> op instanceof Put).forEach(op -> {
Content content = ((Put) op).getContent();
expected.addContent(branch.getName(), content);
});
}
use of org.projectnessie.error.NessieNotFoundException in project nessie by projectnessie.
the class TreeApiImpl method getEntries.
@Override
public EntriesResponse getEntries(String namedRef, EntriesParams params) throws NessieNotFoundException {
Preconditions.checkArgument(params.pageToken() == null, "Paging not supported");
WithHash<NamedRef> refWithHash = namedRefWithHashOrThrow(namedRef, params.hashOnRef());
// all existing VersionStore implementations have to read all keys anyways so we don't get much
try {
List<EntriesResponse.Entry> entries;
try (Stream<EntriesResponse.Entry> entryStream = getStore().getKeys(refWithHash.getHash()).map(key -> EntriesResponse.Entry.builder().name(fromKey(key.getValue())).type((Type) key.getType()).build())) {
Stream<EntriesResponse.Entry> entriesStream = filterEntries(entryStream, params.filter());
if (params.namespaceDepth() != null && params.namespaceDepth() > 0) {
entriesStream = entriesStream.filter(e -> e.getName().getElements().size() >= params.namespaceDepth()).map(e -> truncate(e, params.namespaceDepth())).distinct();
}
entries = entriesStream.collect(ImmutableList.toImmutableList());
}
return EntriesResponse.builder().addAllEntries(entries).build();
} catch (ReferenceNotFoundException e) {
throw new NessieReferenceNotFoundException(e.getMessage(), e);
}
}
use of org.projectnessie.error.NessieNotFoundException in project nessie by projectnessie.
the class TreeApiImplWithAuthorization method createReference.
@Override
public Reference createReference(@Nullable String sourceRefName, Reference reference) throws NessieNotFoundException, NessieConflictException {
BatchAccessChecker check = startAccessCheck().canCreateReference(RefUtil.toNamedRef(reference));
try {
check.canViewReference(namedRefWithHashOrThrow(sourceRefName, reference.getHash()).getValue());
} catch (NessieNotFoundException e) {
// cases, re-throw the exception.
if (!(reference instanceof Branch && reference.getName().equals(getConfig().getDefaultBranch()) && (null == reference.getHash() || getStore().noAncestorHash().asString().equals(reference.getHash())))) {
throw e;
}
}
check.checkAndThrow();
return super.createReference(sourceRefName, reference);
}
Aggregations