Search in sources :

Example 11 with NessieNotFoundException

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);
            }
        });
    }
}
Also used : Operation(org.projectnessie.model.Operation) Detached(org.projectnessie.model.Detached) LogResponse(org.projectnessie.model.LogResponse) Predicate(java.util.function.Predicate) Set(java.util.Set) HashMap(java.util.HashMap) Instant(java.time.Instant) OptionalInt(java.util.OptionalInt) Reference(org.projectnessie.model.Reference) Serializable(java.io.Serializable) NessieApiV1(org.projectnessie.client.api.NessieApiV1) HashSet(java.util.HashSet) Consumer(java.util.function.Consumer) FetchOption(org.projectnessie.api.params.FetchOption) Stream(java.util.stream.Stream) StreamingUtil(org.projectnessie.client.StreamingUtil) Map(java.util.Map) Content(org.projectnessie.model.Content) ContentKey(org.projectnessie.model.ContentKey) Function(org.apache.spark.api.java.function.Function) CommitMeta(org.projectnessie.model.CommitMeta) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) SparkSession(org.apache.spark.sql.SparkSession) Content(org.projectnessie.model.Content) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException)

Example 12 with NessieNotFoundException

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;
}
Also used : Instant(java.time.Instant) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException)

Example 13 with NessieNotFoundException

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);
    });
}
Also used : Put(org.projectnessie.model.Operation.Put) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) Reference(org.projectnessie.model.Reference) NessieConflictException(org.projectnessie.error.NessieConflictException) ArrayList(java.util.ArrayList) Duration(java.time.Duration) Map(java.util.Map) Content(org.projectnessie.model.Content) CommitMeta(org.projectnessie.model.CommitMeta) SparkSession(org.apache.spark.sql.SparkSession) Operation(org.projectnessie.model.Operation) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Branch(org.projectnessie.model.Branch) LogEntry(org.projectnessie.model.LogResponse.LogEntry) Instant(java.time.Instant) NotNull(javax.validation.constraints.NotNull) Objects(java.util.Objects) List(java.util.List) FetchOption(org.projectnessie.api.params.FetchOption) IcebergView(org.projectnessie.model.IcebergView) IcebergTable(org.projectnessie.model.IcebergTable) CONF_NESSIE_URI(org.projectnessie.client.NessieConfigConstants.CONF_NESSIE_URI) AbstractRest(org.projectnessie.jaxrs.AbstractRest) ContentKey(org.projectnessie.model.ContentKey) Comparator(java.util.Comparator) CommitMultipleOperationsBuilder(org.projectnessie.client.api.CommitMultipleOperationsBuilder) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) Content(org.projectnessie.model.Content) Collection(java.util.Collection) LogEntry(org.projectnessie.model.LogResponse.LogEntry) Put(org.projectnessie.model.Operation.Put)

Example 14 with NessieNotFoundException

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);
    }
}
Also used : Detached(org.projectnessie.model.Detached) TreeApi(org.projectnessie.api.TreeApi) ServerConfig(org.projectnessie.services.config.ServerConfig) VAR_REF_TYPE(org.projectnessie.services.cel.CELUtil.VAR_REF_TYPE) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) NessieConflictException(org.projectnessie.error.NessieConflictException) GetNamedRefsParams(org.projectnessie.versioned.GetNamedRefsParams) VAR_REF(org.projectnessie.services.cel.CELUtil.VAR_REF) VersionStore(org.projectnessie.versioned.VersionStore) Delete(org.projectnessie.versioned.Delete) Type(org.projectnessie.model.Content.Type) Map(java.util.Map) Content(org.projectnessie.model.Content) Ref(org.projectnessie.versioned.Ref) NamedRef(org.projectnessie.versioned.NamedRef) VAR_CONTENT_TYPE(org.projectnessie.services.cel.CELUtil.VAR_CONTENT_TYPE) ScriptException(org.projectnessie.cel.tools.ScriptException) ImmutableMap(com.google.common.collect.ImmutableMap) Validation(org.projectnessie.model.Validation) ReferencesResponse(org.projectnessie.model.ReferencesResponse) REFERENCES_DECLARATIONS(org.projectnessie.services.cel.CELUtil.REFERENCES_DECLARATIONS) Branch(org.projectnessie.model.Branch) LogEntry(org.projectnessie.model.LogResponse.LogEntry) ReferenceAlreadyExistsException(org.projectnessie.versioned.ReferenceAlreadyExistsException) EntriesResponse(org.projectnessie.model.EntriesResponse) COMMIT_LOG_TYPES(org.projectnessie.services.cel.CELUtil.COMMIT_LOG_TYPES) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) BranchName(org.projectnessie.versioned.BranchName) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) List(java.util.List) Principal(java.security.Principal) Stream(java.util.stream.Stream) ENTRIES_DECLARATIONS(org.projectnessie.services.cel.CELUtil.ENTRIES_DECLARATIONS) Transplant(org.projectnessie.model.Transplant) ImmutableReferencesResponse(org.projectnessie.model.ImmutableReferencesResponse) Optional(java.util.Optional) ContentKey(org.projectnessie.model.ContentKey) CELUtil(org.projectnessie.services.cel.CELUtil) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) Put(org.projectnessie.versioned.Put) ReferenceMetadata(org.projectnessie.model.ReferenceMetadata) LogResponse(org.projectnessie.model.LogResponse) NessieReferenceAlreadyExistsException(org.projectnessie.error.NessieReferenceAlreadyExistsException) Authorizer(org.projectnessie.services.authz.Authorizer) VAR_ENTRY(org.projectnessie.services.cel.CELUtil.VAR_ENTRY) TagName(org.projectnessie.versioned.TagName) Reference(org.projectnessie.model.Reference) Strings(com.google.common.base.Strings) Script(org.projectnessie.cel.tools.Script) COMMIT_LOG_DECLARATIONS(org.projectnessie.services.cel.CELUtil.COMMIT_LOG_DECLARATIONS) ImmutableLogResponse(org.projectnessie.model.ImmutableLogResponse) ImmutableList(com.google.common.collect.ImmutableList) GetReferenceParams(org.projectnessie.api.params.GetReferenceParams) ReferencesParams(org.projectnessie.api.params.ReferencesParams) Merge(org.projectnessie.model.Merge) NessieReferenceConflictException(org.projectnessie.error.NessieReferenceConflictException) StreamSupport(java.util.stream.StreamSupport) CommitMeta(org.projectnessie.model.CommitMeta) ImmutableLogEntry(org.projectnessie.model.ImmutableLogEntry) Nullable(javax.annotation.Nullable) VAR_COMMIT(org.projectnessie.services.cel.CELUtil.VAR_COMMIT) WithHash(org.projectnessie.versioned.WithHash) Operation(org.projectnessie.model.Operation) REFERENCES_TYPES(org.projectnessie.services.cel.CELUtil.REFERENCES_TYPES) CommitLogParams(org.projectnessie.api.params.CommitLogParams) Hash(org.projectnessie.versioned.Hash) ImmutableTag(org.projectnessie.model.ImmutableTag) ImmutableBranch(org.projectnessie.model.ImmutableBranch) SCRIPT_HOST(org.projectnessie.services.cel.CELUtil.SCRIPT_HOST) Commit(org.projectnessie.versioned.Commit) ImmutableReferenceMetadata(org.projectnessie.model.ImmutableReferenceMetadata) CONTAINER(org.projectnessie.services.cel.CELUtil.CONTAINER) VAR_NAMESPACE(org.projectnessie.services.cel.CELUtil.VAR_NAMESPACE) Key(org.projectnessie.versioned.Key) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) VAR_REF_META(org.projectnessie.services.cel.CELUtil.VAR_REF_META) RetrieveOptions(org.projectnessie.versioned.GetNamedRefsParams.RetrieveOptions) EntriesParams(org.projectnessie.api.params.EntriesParams) FetchOption(org.projectnessie.api.params.FetchOption) Operations(org.projectnessie.model.Operations) ReferenceInfo(org.projectnessie.versioned.ReferenceInfo) Preconditions(com.google.common.base.Preconditions) RefUtil.toNamedRef(org.projectnessie.services.impl.RefUtil.toNamedRef) Collections(java.util.Collections) VAR_OPERATIONS(org.projectnessie.services.cel.CELUtil.VAR_OPERATIONS) Unchanged(org.projectnessie.versioned.Unchanged) LogEntry(org.projectnessie.model.LogResponse.LogEntry) ImmutableLogEntry(org.projectnessie.model.ImmutableLogEntry) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) NamedRef(org.projectnessie.versioned.NamedRef) RefUtil.toNamedRef(org.projectnessie.services.impl.RefUtil.toNamedRef)

Example 15 with NessieNotFoundException

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);
}
Also used : BatchAccessChecker(org.projectnessie.services.authz.BatchAccessChecker) Branch(org.projectnessie.model.Branch) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException)

Aggregations

NessieNotFoundException (org.projectnessie.error.NessieNotFoundException)19 Content (org.projectnessie.model.Content)12 ContentKey (org.projectnessie.model.ContentKey)10 Map (java.util.Map)8 Branch (org.projectnessie.model.Branch)8 Reference (org.projectnessie.model.Reference)8 NessieConflictException (org.projectnessie.error.NessieConflictException)7 List (java.util.List)5 Stream (java.util.stream.Stream)5 CommitFailedException (org.apache.iceberg.exceptions.CommitFailedException)5 CommitStateUnknownException (org.apache.iceberg.exceptions.CommitStateUnknownException)5 NoSuchTableException (org.apache.iceberg.exceptions.NoSuchTableException)5 HttpClientException (org.projectnessie.client.http.HttpClientException)5 Operation (org.projectnessie.model.Operation)5 Instant (java.time.Instant)4 Set (java.util.Set)4 FetchOption (org.projectnessie.api.params.FetchOption)4 CommitMultipleOperationsBuilder (org.projectnessie.client.api.CommitMultipleOperationsBuilder)4 CommitMeta (org.projectnessie.model.CommitMeta)4 HashMap (java.util.HashMap)3