Skip to content

Commit

Permalink
Allow null prevEndRow for creating a tablet in split
Browse files Browse the repository at this point in the history
  • Loading branch information
dlmarion committed Oct 18, 2023
1 parent bda3e75 commit 8098890
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ public class ConditionalTabletMutatorImpl extends TabletMutatorBase<Ample.Condit
private final ConditionalMutation mutation;
private final Consumer<ConditionalMutation> mutationConsumer;
private final Ample.ConditionalTabletsMutator parent;
private final boolean prevEndRowSupplied;

private final BiConsumer<KeyExtent,Ample.RejectionHandler> rejectionHandlerConsumer;

private final KeyExtent extent;

private boolean sawOperationRequirement = false;
private boolean requireAbsentTabletCalled = false;

protected ConditionalTabletMutatorImpl(Ample.ConditionalTabletsMutator parent,
ServerContext context, KeyExtent extent, Text prevEndRow,
Expand All @@ -86,10 +88,17 @@ protected ConditionalTabletMutatorImpl(Ample.ConditionalTabletsMutator parent,
this.rejectionHandlerConsumer = rejectionHandlerConsumer;
this.extent = extent;

Condition c =
new Condition(PREV_ROW_COLUMN.getColumnFamily(), PREV_ROW_COLUMN.getColumnQualifier())
.setValue(TabletColumnFamily.encodePrevEndRow(prevEndRow).get());
mutation.addCondition(c);
// If prevEndRow is null, then we are creating a new Tablet in which case
// there is no prevEndRow.
if (prevEndRow != null) {
Condition c =
new Condition(PREV_ROW_COLUMN.getColumnFamily(), PREV_ROW_COLUMN.getColumnQualifier())
.setValue(TabletColumnFamily.encodePrevEndRow(prevEndRow).get());
mutation.addCondition(c);
prevEndRowSupplied = true;
} else {
prevEndRowSupplied = false;
}
}

@Override
Expand Down Expand Up @@ -139,6 +148,7 @@ public Ample.ConditionalTabletMutator requireAbsentTablet() {
Condition c = new Condition("", "").setIterators(is);
mutation.addCondition(c);
sawOperationRequirement = true;
requireAbsentTabletCalled = true;
return this;
}

Expand Down Expand Up @@ -244,6 +254,9 @@ public Ample.ConditionalTabletMutator requireSame(TabletMetadata tabletMetadata,
public void submit(Ample.RejectionHandler rejectionCheck) {
Preconditions.checkState(updatesEnabled, "Cannot make updates after calling mutate.");
Preconditions.checkState(sawOperationRequirement, "No operation requirements were seen");
if (!prevEndRowSupplied && !requireAbsentTabletCalled) {
requireAbsentTablet();
}
getMutation();
mutationConsumer.accept(mutation);
rejectionHandlerConsumer.accept(extent, rejectionCheck);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ private void addNewTablets(long tid, Manager manager, TabletMetadata tabletMetad
continue;
}

var mutator =
tabletsMutator.mutateTablet(newExtent, newExtent.prevEndRow()).requireAbsentTablet();
var mutator = tabletsMutator.mutateTablet(newExtent, null).requireAbsentTablet();

mutator.putOperation(opid);
mutator.putDirName(dirNameIter.next());
Expand Down

0 comments on commit 8098890

Please sign in to comment.