-
Notifications
You must be signed in to change notification settings - Fork 117
Introduce KeySpacePath.importData to import previously exported data #3578
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
Changes from 14 commits
178cd61
938d240
bee1806
44d609b
b810497
9132184
f63ae18
714faf3
c255044
f30cb54
287ff3f
2cac9f3
77d85a2
afc98fb
7dfcb34
e6b605e
7a4e127
40055dd
4c9b11e
1a23763
0fb43b9
0ec5181
30b9a01
1f78a84
813f6e3
3099acd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -316,6 +316,43 @@ public RecordCursor<DataInKeySpacePath> exportAllData(@Nonnull FDBRecordContext | |
| 1); | ||
| } | ||
|
|
||
| @Nonnull | ||
| @Override | ||
| public CompletableFuture<Void> importData(@Nonnull FDBRecordContext context, | ||
ohadzeliger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @Nonnull Iterable<DataInKeySpacePath> dataToImport) { | ||
| return toTupleAsync(context).thenCompose(targetTuple -> { | ||
| List<CompletableFuture<Void>> importFutures = new ArrayList<>(); | ||
|
|
||
| for (DataInKeySpacePath dataItem : dataToImport) { | ||
| CompletableFuture<Void> importFuture = dataItem.getPath().toTupleAsync(context).thenCompose(itemPathTuple -> { | ||
ohadzeliger marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // Validate that this data belongs under this path | ||
| if (!TupleHelpers.isPrefix(targetTuple, itemPathTuple)) { | ||
| throw new RecordCoreIllegalImportDataException( | ||
| "Data item path does not belong under target path", | ||
| "target", targetTuple, | ||
| "item", itemPathTuple); | ||
| } | ||
|
|
||
| // Reconstruct the key using the path and remainder | ||
| Tuple keyTuple = itemPathTuple; | ||
| if (dataItem.getRemainder() != null) { | ||
| keyTuple = keyTuple.addAll(dataItem.getRemainder()); | ||
| } | ||
|
|
||
| // Store the data | ||
| byte[] keyBytes = keyTuple.pack(); | ||
|
||
| byte[] valueBytes = dataItem.getValue(); | ||
| context.ensureActive().set(keyBytes, valueBytes); | ||
|
|
||
| return AsyncUtil.DONE; | ||
| }); | ||
| importFutures.add(importFuture); | ||
| } | ||
|
|
||
| return AsyncUtil.whenAll(importFutures); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Returns this path properly wrapped in whatever implementation the directory the path is contained in dictates. | ||
| */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * RecordCoreIllegalImportDataException.java | ||
| * | ||
| * This source file is part of the FoundationDB open source project | ||
| * | ||
| * Copyright 2015-2025 Apple Inc. and the FoundationDB project authors | ||
| * | ||
| * 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 com.apple.foundationdb.record.provider.foundationdb.keyspace; | ||
|
|
||
| import com.apple.foundationdb.record.RecordCoreArgumentException; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
|
|
||
| /** | ||
| * Thrown if the data being imported into {@link KeySpacePath#importData} does not belong in that path. | ||
| */ | ||
| public class RecordCoreIllegalImportDataException extends RecordCoreArgumentException { | ||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| public RecordCoreIllegalImportDataException(@Nonnull final String msg, @Nonnull final Object... keyValue) { | ||
| super(msg, keyValue); | ||
| } | ||
| } | ||
|
Check warning on line 36 in fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/keyspace/RecordCoreIllegalImportDataException.java
|
||
Uh oh!
There was an error while loading. Please reload this page.