-
Notifications
You must be signed in to change notification settings - Fork 488
New Presplit utility for Fate table #6471
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -18,6 +18,13 @@ | |||||
| */ | ||||||
| package org.apache.accumulo.server.util.adminCommand; | ||||||
|
|
||||||
| import static java.nio.charset.StandardCharsets.UTF_8; | ||||||
|
|
||||||
| import java.io.BufferedWriter; | ||||||
| import java.io.OutputStreamWriter; | ||||||
| import java.io.PrintWriter; | ||||||
| import java.nio.file.Files; | ||||||
| import java.nio.file.Path; | ||||||
| import java.util.ArrayList; | ||||||
| import java.util.Collection; | ||||||
| import java.util.Collections; | ||||||
|
|
@@ -79,6 +86,7 @@ | |||||
| import com.beust.jcommander.JCommander; | ||||||
| import com.beust.jcommander.Parameter; | ||||||
| import com.google.auto.service.AutoService; | ||||||
| import com.google.common.base.Preconditions; | ||||||
|
|
||||||
| @AutoService(KeywordExecutable.class) | ||||||
| public class Fate extends ServerKeywordExecutable<FateOpts> { | ||||||
|
|
@@ -152,6 +160,14 @@ static class FateOpts extends ServerOpts { | |||||
| @Parameter(names = {"-i", "--info"}, | ||||||
| description = "Includes detailed transaction information when printing") | ||||||
| boolean printDetails; | ||||||
|
|
||||||
| @Parameter(names = {"-n", "--numSplits"}, | ||||||
| description = "Generate N split points for the fate table and print to stdout. N should always be greater than 1.") | ||||||
| int numSplits = 1; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think we need to default to -1 here so that split generation is opt-in. If we leave it as |
||||||
|
|
||||||
| @Parameter(names = {"-sf", "--splitsFile"}, | ||||||
| description = "Write split points to a file. Used with -n or --num-splits.") | ||||||
| String splitsFile = null; | ||||||
| } | ||||||
|
|
||||||
| private final CountDownLatch lockAcquiredLatch = new CountDownLatch(1); | ||||||
|
|
@@ -218,6 +234,10 @@ public void execute(JCommander cl, FateOpts options) throws Exception { | |||||
| Map<FateInstanceType,ReadOnlyFateStore<Fate>> readOnlyFateStores = null; | ||||||
|
|
||||||
| try { | ||||||
| if (options.numSplits > 0) { | ||||||
| preSplitFateTable(options); | ||||||
| return; | ||||||
| } | ||||||
| if (options.cancel) { | ||||||
| cancelSubmittedFateTxs(context, options.fateIdList); | ||||||
| } else if (options.fail) { | ||||||
|
|
@@ -267,6 +287,38 @@ public void execute(JCommander cl, FateOpts options) throws Exception { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| private void preSplitFateTable(FateOpts options) throws Exception { | ||||||
| List<String> splits = generateSplits(options.numSplits); | ||||||
|
|
||||||
| if (options.splitsFile != null) { | ||||||
| try (PrintWriter writer = new PrintWriter(new BufferedWriter( | ||||||
| new OutputStreamWriter(Files.newOutputStream(Path.of(options.splitsFile)), UTF_8)))) { | ||||||
|
Comment on lines
+294
to
+295
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I usually try not to nest constructors in a try-with-resources block. Usually things work out okay but putting each object constructed on its own line makes it more certain that each object will be cleaned up properly in the try-with-resources block as opposed to relying on the closure of the outmost object to cascade down and close the rest. |
||||||
| splits.forEach(writer::println); | ||||||
| } | ||||||
| System.out.println("Wrote " + splits.size() + " split point(s) to " + options.splitsFile); | ||||||
| } else { | ||||||
| splits.forEach(System.out::println); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| static List<String> generateSplits(int numSplits) { | ||||||
| Preconditions.checkArgument(numSplits >= 1, | ||||||
| "Number of splits must be greater than 1. Specifying 0 would generate no splits and leave the table unchanged.", | ||||||
| numSplits); | ||||||
|
|
||||||
| // Same logic as in FateManager.getDesiredPartitions() | ||||||
| // Work w/ 60 bit unsigned integers to partition the space and then shift over by 4. Used 60 | ||||||
| // bits instead of 63 so it nicely aligns w/ hex in the uuid. | ||||||
| long jump = (1L << 60) / (numSplits + 1); | ||||||
| List<String> splits = new ArrayList<>(numSplits); | ||||||
| for (int i = 1; i <= numSplits; i++) { | ||||||
| long start = (i * jump) << 4; | ||||||
| splits.add(new UUID(start, 0).toString()); | ||||||
| } | ||||||
|
|
||||||
| return Collections.unmodifiableList(splits); | ||||||
| } | ||||||
|
|
||||||
| private FateStores createFateStores(ServerContext context, ZooSession zk, ServiceLock adminLock) | ||||||
| throws InterruptedException, KeeperException { | ||||||
| var lockId = adminLock.getLockID(); | ||||||
|
|
@@ -323,6 +375,13 @@ private void validateFateUserInput(FateOpts cmd) { | |||||
| throw new IllegalArgumentException( | ||||||
| "At least one txId required when using cancel, fail or delete"); | ||||||
| } | ||||||
| if (cmd.numSplits == 0) { | ||||||
| throw new IllegalArgumentException( | ||||||
| "-n / --num-splits must be >= 1. Specifying 0 generates no splits and leaves the table unchanged."); | ||||||
| } | ||||||
| if (cmd.splitsFile != null && cmd.numSplits < 0) { | ||||||
| throw new IllegalArgumentException("-sf requires -n to also be specified."); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| private void cancelSubmittedFateTxs(ServerContext context, List<String> fateIdList) | ||||||
|
|
||||||
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.