-
Notifications
You must be signed in to change notification settings - Fork 487
Human-readable metadata scan #6519
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 |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| import java.io.FileNotFoundException; | ||
| import java.io.IOException; | ||
| import java.io.UnsupportedEncodingException; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.Map.Entry; | ||
|
|
@@ -40,7 +41,11 @@ | |
| import org.apache.accumulo.core.data.Range; | ||
| import org.apache.accumulo.core.data.Value; | ||
| import org.apache.accumulo.core.iterators.SortedKeyValueIterator; | ||
| import org.apache.accumulo.core.metadata.StoredTabletFile; | ||
| import org.apache.accumulo.core.metadata.SystemTables; | ||
| import org.apache.accumulo.core.metadata.schema.MetadataSchema; | ||
| import org.apache.accumulo.core.security.Authorizations; | ||
| import org.apache.accumulo.core.util.format.DefaultFormatter; | ||
| import org.apache.accumulo.core.util.format.Formatter; | ||
| import org.apache.accumulo.core.util.format.FormatterConfig; | ||
| import org.apache.accumulo.shell.Shell; | ||
|
|
@@ -75,6 +80,7 @@ public class ScanCommand extends Command { | |
| protected Option contextOpt; | ||
| private Option executionHintsOpt; | ||
| private Option scanServerOpt; | ||
| private Option decodeMetadataOpt; | ||
|
|
||
| protected void setupSampling(final String tableName, final CommandLine cl, final Shell shellState, | ||
| ScannerBase scanner) | ||
|
|
@@ -155,12 +161,54 @@ public int execute(final String fullCommand, final CommandLine cl, final Shell s | |
| Shell.log.error("Invalid length argument", iae); | ||
| } | ||
| } | ||
| printRecords(cl, shellState, config, scanner, formatter, printFile); | ||
| boolean decodeMetadata = cl.hasOption(decodeMetadataOpt.getLongOpt()) | ||
| && (tableName.equals(SystemTables.METADATA.tableName()) | ||
| || tableName.equals(SystemTables.ROOT.tableName())); | ||
|
|
||
| if (decodeMetadata) { | ||
| printRecordsWithDecodedRanges(cl, shellState, config, scanner, printFile); | ||
| } else { | ||
| printRecords(cl, shellState, config, scanner, formatter, printFile); | ||
| } | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| private void printRecordsWithDecodedRanges(final CommandLine cl, final Shell shellState, | ||
| final FormatterConfig config, final Scanner scanner, final PrintFile printFile) | ||
| throws IOException { | ||
|
|
||
| final Text fileCf = new Text(MetadataSchema.TabletsSection.DataFileColumnFamily.STR_NAME); | ||
| final Text scanCf = new Text(MetadataSchema.TabletsSection.ScanFileColumnFamily.STR_NAME); | ||
|
|
||
| final List<String> lines = new ArrayList<>(); | ||
|
|
||
| for (Entry<Key,Value> entry : scanner) { | ||
| Text cf = entry.getKey().getColumnFamily(); | ||
|
|
||
| if (fileCf.equals(cf) || scanCf.equals(cf)) { | ||
| String metadataRow = entry.getKey().getRow().toString(); | ||
| String cq = entry.getKey().getColumnQualifier().toString(); | ||
| try { | ||
| StoredTabletFile stf = StoredTabletFile.of(cq); | ||
| lines.add(metadataRow + "\t" + stf.toMinimalString()); | ||
| } catch (RuntimeException e) { | ||
| lines.add(DefaultFormatter.formatEntry(entry, config)); | ||
| } | ||
| } else { | ||
| // All non-file columns (loc:, srv:, ~tab:, etc.) use normal formatting | ||
| lines.add(DefaultFormatter.formatEntry(entry, config)); | ||
| } | ||
| } | ||
|
|
||
| if (printFile == null) { | ||
| shellState.printLines(lines.iterator(), !cl.hasOption(disablePaginationOpt.getOpt())); | ||
| } else { | ||
| shellState.printLines(lines.iterator(), false, printFile); | ||
| } | ||
| } | ||
|
|
||
| protected boolean getUseSample(CommandLine cl) { | ||
| return cl.hasOption(sampleOpt.getLongOpt()); | ||
| } | ||
|
|
@@ -352,6 +400,8 @@ public Options getOptions() { | |
| executionHintsOpt = new Option(null, "execution-hints", true, "Execution hints map"); | ||
| scanServerOpt = | ||
| new Option("cl", "consistency-level", true, "set consistency level (experimental)"); | ||
| decodeMetadataOpt = new Option("dm", "decode-metadata", false, | ||
|
Contributor
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'm not sure that we need an option. If the user has the ability to scan the metadata, then we should just show them the un-obfuscated metadata entry.
Contributor
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. Doesn't accumulo already have formatters? metadataformatter that extends default formatter could be a better option and obviate the need for an option. also could be default?
Contributor
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. It's a good idea, but I think the intention is to remove formatters. See #3265.
Contributor
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. Yes, thank you. I encountered this last year sometime when testing 4.0, but I have a very poor memory.... Should this option be flipped? On by default, old method an option just in case someone relies on the encoded form? I think it's pretty fair to say 4.0 changes the output, though. |
||
| "Decode fenced file row ranges from metadata and root tables"); | ||
|
|
||
| scanOptAuths.setArgName("comma-separated-authorizations"); | ||
| scanOptRow.setArgName("row"); | ||
|
|
@@ -366,6 +416,7 @@ public Options getOptions() { | |
| contextOpt.setArgName("context"); | ||
| executionHintsOpt.setArgName("<key>=<value>{,<key>=<value>}"); | ||
| scanServerOpt.setArgName("immediate|eventual"); | ||
| decodeMetadataOpt.setArgName("decode-metadata"); | ||
|
|
||
| profileOpt = new Option("pn", "profile", true, "iterator profile name"); | ||
| profileOpt.setArgName("profile"); | ||
|
|
@@ -398,6 +449,7 @@ public Options getOptions() { | |
| o.addOption(contextOpt); | ||
| o.addOption(executionHintsOpt); | ||
| o.addOption(scanServerOpt); | ||
| o.addOption(decodeMetadataOpt); | ||
|
|
||
| return o; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,9 +68,8 @@ public class FileMetadataUtil { | |
| StoredTabletFile file = fileEntry.getKey(); | ||
| DataFileValue dfv = fileEntry.getValue(); | ||
| files.put(file, dfv); | ||
| log.debug("Extent: " + tabletMetadata.getExtent() + "; File Name: " + file.getFileName() | ||
| + "; Range: " + file.getRange() + "; Entries: " + dfv.getNumEntries() + ", Size: " | ||
| + dfv.getSize()); | ||
| log.debug("Extent: {}; File: {}; Entries: {}; Size: {}", tabletMetadata.getExtent(), file, | ||
|
Contributor
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. Was the change above in |
||
| dfv.getNumEntries(), dfv.getSize()); | ||
| i++; | ||
| } | ||
| } | ||
|
|
||
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.
Wouldn't this affect every log line and exception message that stringifies . Would this create some kind of diagnostics regression if anyone is consuming logs for alterting? Should this be moved to the call sites that need it?
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.
That's where I was going with my other comment. If this change was only made to support the logging change, then I think it should be reverted. I don't think logging changes are an issue for the 4.0 release, but I'm more concerned about some code using the output of
toStringby mistake and the unintended consequences of changing it.Uh oh!
There was an error while loading. Please reload this page.
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.
I was less concerned about programmatic usage and more concerned about logs given how they could be used in cloud deployments -- but I think the end result is the same: if the fidelity is changing as a result of this change would any downstream consumer have to change processes?
If the answer is yes, then is the ROI of this change in its favor ?
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.
I should use AI to comment so I don't have so many typos...