-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New storage: allow deletion of multiple repositories #6758
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
.../java/org/projectnessie/versioned/storage/commontests/AbstractBackendRepositoryTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (C) 2022 Dremio | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.projectnessie.versioned.storage.commontests; | ||
|
||
import static org.projectnessie.versioned.storage.common.logic.Logics.repositoryLogic; | ||
|
||
import java.util.EnumSet; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
import org.assertj.core.api.SoftAssertions; | ||
import org.assertj.core.api.junit.jupiter.InjectSoftAssertions; | ||
import org.assertj.core.api.junit.jupiter.SoftAssertionsExtension; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
import org.projectnessie.versioned.storage.common.config.StoreConfig; | ||
import org.projectnessie.versioned.storage.common.logic.RepositoryLogic; | ||
import org.projectnessie.versioned.storage.common.persist.Backend; | ||
import org.projectnessie.versioned.storage.common.persist.CloseableIterator; | ||
import org.projectnessie.versioned.storage.common.persist.Obj; | ||
import org.projectnessie.versioned.storage.common.persist.ObjType; | ||
import org.projectnessie.versioned.storage.common.persist.Persist; | ||
import org.projectnessie.versioned.storage.common.persist.PersistFactory; | ||
import org.projectnessie.versioned.storage.testextension.NessiePersist; | ||
import org.projectnessie.versioned.storage.testextension.PersistExtension; | ||
|
||
/** Basic {@link Persist} tests to be run by every implementation. */ | ||
@ExtendWith({PersistExtension.class, SoftAssertionsExtension.class}) | ||
public class AbstractBackendRepositoryTests { | ||
@InjectSoftAssertions protected SoftAssertions soft; | ||
|
||
@NessiePersist protected Backend backend; | ||
@NessiePersist protected PersistFactory persistFactory; | ||
|
||
@Test | ||
public void createEraseRepoViaPersist() { | ||
Persist repo1 = newRepo(); | ||
|
||
RepositoryLogic repositoryLogic = repositoryLogic(repo1); | ||
repositoryLogic.initialize("foo-main"); | ||
soft.assertThat(repositoryLogic.repositoryExists()).isTrue(); | ||
repo1.erase(); | ||
soft.assertThat(repositoryLogic.repositoryExists()).isFalse(); | ||
try (CloseableIterator<Obj> scan = repo1.scanAllObjects(EnumSet.allOf(ObjType.class))) { | ||
soft.assertThat(scan).isExhausted(); | ||
} | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(ints = {1, 3, 10}) | ||
public void createEraseManyRepos(int numRepos) { | ||
List<Persist> repos = | ||
IntStream.range(0, numRepos).mapToObj(x -> newRepo()).collect(Collectors.toList()); | ||
|
||
repos.forEach(r -> repositoryLogic(r).initialize("foo-meep")); | ||
soft.assertThat(repos).allMatch(r -> repositoryLogic(r).repositoryExists()); | ||
backend.eraseRepositories( | ||
repos.stream().map(r -> r.config().repositoryId()).collect(Collectors.toSet())); | ||
soft.assertThat(repos).noneMatch(r -> repositoryLogic(r).repositoryExists()); | ||
soft.assertThat(repos) | ||
.noneMatch( | ||
r -> { | ||
try (CloseableIterator<Obj> scan = r.scanAllObjects(EnumSet.allOf(ObjType.class))) { | ||
return scan.hasNext(); | ||
} | ||
}); | ||
} | ||
|
||
private Persist newRepo() { | ||
return persistFactory.newPersist( | ||
StoreConfig.Adjustable.empty().withRepositoryId("repo-" + UUID.randomUUID())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...orage/dynamodb/src/main/java/org/projectnessie/versioned/storage/dynamodb/BatchWrite.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (C) 2023 Dremio | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.projectnessie.versioned.storage.dynamodb; | ||
|
||
import static java.util.Collections.singletonMap; | ||
import static org.projectnessie.versioned.storage.dynamodb.DynamoDBConstants.BATCH_WRITE_MAX_REQUESTS; | ||
import static org.projectnessie.versioned.storage.dynamodb.DynamoDBConstants.KEY_NAME; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import software.amazon.awssdk.services.dynamodb.model.AttributeValue; | ||
import software.amazon.awssdk.services.dynamodb.model.WriteRequest; | ||
|
||
final class BatchWrite implements AutoCloseable { | ||
private final DynamoDBBackend backend; | ||
private final String tableName; | ||
private final List<WriteRequest> requestItems = new ArrayList<>(); | ||
|
||
BatchWrite(DynamoDBBackend backend, String tableName) { | ||
this.backend = backend; | ||
this.tableName = tableName; | ||
} | ||
|
||
private void addRequest(WriteRequest.Builder request) { | ||
requestItems.add(request.build()); | ||
if (requestItems.size() == BATCH_WRITE_MAX_REQUESTS) { | ||
flush(); | ||
} | ||
} | ||
|
||
void addDelete(AttributeValue key) { | ||
addRequest(WriteRequest.builder().deleteRequest(b -> b.key(singletonMap(KEY_NAME, key)))); | ||
} | ||
|
||
public void addPut(Map<String, AttributeValue> item) { | ||
addRequest(WriteRequest.builder().putRequest(b -> b.item(item))); | ||
} | ||
|
||
// close() is actually a flush, implementing AutoCloseable for easier use of BatchDelete using | ||
// try-with-resources. | ||
@Override | ||
public void close() { | ||
if (!requestItems.isEmpty()) { | ||
flush(); | ||
} | ||
} | ||
|
||
private void flush() { | ||
backend.client().batchWriteItem(b -> b.requestItems(singletonMap(tableName, requestItems))); | ||
requestItems.clear(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we go above
MAX_CONCURRENT_DELETES
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops - saw it too late - #6768