@Test(expected = IllegalStateException.class) public void testFutureAndCurrent() { KeyExtent extent = new KeyExtent(TableId.of("5"), new Text("df"), new Text("da")); Mutation mutation = TabletColumnFamily.createPrevRowMutation(extent); mutation.at().family(CurrentLocationColumnFamily.NAME).qualifier("s001").put("server1:8555"); mutation.at().family(FutureLocationColumnFamily.NAME).qualifier("s001").put("server1:8555"); SortedMap<Key,Value> rowMap = toRowMap(mutation); TabletMetadata.convertRow(rowMap.entrySet().iterator(), EnumSet.allOf(ColumnType.class), false); }
@VisibleForTesting public static TabletMetadata convertRow(Iterator<Entry<Key,Value>> rowIter, EnumSet<ColumnType> fetchedColumns, boolean buildKeyValueMap) { Objects.requireNonNull(rowIter); TabletMetadata te = new TabletMetadata(); ImmutableSortedMap.Builder<Key,Value> kvBuilder = null; if (buildKeyValueMap) { kvBuilder = ImmutableSortedMap.naturalOrder(); } var filesBuilder = ImmutableMap.<StoredTabletFile,DataFileValue>builder(); var scansBuilder = ImmutableList.<StoredTabletFile>builder(); var logsBuilder = ImmutableList.<LogEntry>builder(); final var loadedFilesBuilder = ImmutableMap.<TabletFile,Long>builder(); ByteSequence row = null; while (rowIter.hasNext()) { final Entry<Key,Value> kv = rowIter.next(); final Key key = kv.getKey(); final String val = kv.getValue().toString(); final String fam = key.getColumnFamilyData().toString(); final String qual = key.getColumnQualifierData().toString(); if (buildKeyValueMap) { kvBuilder.put(key, kv.getValue()); } if (row == null) { row = key.getRowData(); KeyExtent ke = KeyExtent.fromMetaRow(key.getRow()); te.endRow = ke.endRow(); te.tableId = ke.tableId(); } else if (!row.equals(key.getRowData())) { throw new IllegalArgumentException( "Input contains more than one row : " + row + " " + key.getRowData()); } switch (fam.toString()) { case TabletColumnFamily.STR_NAME: switch (qual) { case PREV_ROW_QUAL: te.prevEndRow = TabletColumnFamily.decodePrevEndRow(kv.getValue()); te.sawPrevEndRow = true; break; case OLD_PREV_ROW_QUAL: te.oldPrevEndRow = TabletColumnFamily.decodePrevEndRow(kv.getValue()); te.sawOldPrevEndRow = true; break; case SPLIT_RATIO_QUAL: te.splitRatio = Double.parseDouble(val); break; } break; case ServerColumnFamily.STR_NAME: switch (qual) { case DIRECTORY_QUAL: Preconditions.checkArgument(ServerColumnFamily.isValidDirCol(val), "Saw invalid dir name {} {}", key, val); te.dirName = val; break; case TIME_QUAL: te.time = MetadataTime.parse(val); break; case FLUSH_QUAL: te.flush = OptionalLong.of(Long.parseLong(val)); break; case COMPACT_QUAL: te.compact = OptionalLong.of(Long.parseLong(val)); break; } break; case DataFileColumnFamily.STR_NAME: filesBuilder.put(new StoredTabletFile(qual), new DataFileValue(val)); break; case BulkFileColumnFamily.STR_NAME: loadedFilesBuilder.put(new StoredTabletFile(qual), BulkFileColumnFamily.getBulkLoadTid(val)); break; case CurrentLocationColumnFamily.STR_NAME: te.setLocationOnce(val, qual, LocationType.CURRENT); break; case FutureLocationColumnFamily.STR_NAME: te.setLocationOnce(val, qual, LocationType.FUTURE); break; case LastLocationColumnFamily.STR_NAME: te.last = new Location(val, qual, LocationType.LAST); break; case ScanFileColumnFamily.STR_NAME: scansBuilder.add(new StoredTabletFile(qual)); break; case ClonedColumnFamily.STR_NAME: te.cloned = val; break; case LogColumnFamily.STR_NAME: logsBuilder.add(LogEntry.fromMetaWalEntry(kv)); break; default: throw new IllegalStateException("Unexpected family " + fam); } } te.files = filesBuilder.build(); te.loadedFiles = loadedFilesBuilder.build(); te.fetchedCols = fetchedColumns; te.scans = scansBuilder.build(); te.logs = logsBuilder.build(); if (buildKeyValueMap) { te.keyValues = kvBuilder.build(); } return te; }
TabletMetadata { @VisibleForTesting public static TabletMetadata convertRow(Iterator<Entry<Key,Value>> rowIter, EnumSet<ColumnType> fetchedColumns, boolean buildKeyValueMap) { Objects.requireNonNull(rowIter); TabletMetadata te = new TabletMetadata(); ImmutableSortedMap.Builder<Key,Value> kvBuilder = null; if (buildKeyValueMap) { kvBuilder = ImmutableSortedMap.naturalOrder(); } var filesBuilder = ImmutableMap.<StoredTabletFile,DataFileValue>builder(); var scansBuilder = ImmutableList.<StoredTabletFile>builder(); var logsBuilder = ImmutableList.<LogEntry>builder(); final var loadedFilesBuilder = ImmutableMap.<TabletFile,Long>builder(); ByteSequence row = null; while (rowIter.hasNext()) { final Entry<Key,Value> kv = rowIter.next(); final Key key = kv.getKey(); final String val = kv.getValue().toString(); final String fam = key.getColumnFamilyData().toString(); final String qual = key.getColumnQualifierData().toString(); if (buildKeyValueMap) { kvBuilder.put(key, kv.getValue()); } if (row == null) { row = key.getRowData(); KeyExtent ke = KeyExtent.fromMetaRow(key.getRow()); te.endRow = ke.endRow(); te.tableId = ke.tableId(); } else if (!row.equals(key.getRowData())) { throw new IllegalArgumentException( "Input contains more than one row : " + row + " " + key.getRowData()); } switch (fam.toString()) { case TabletColumnFamily.STR_NAME: switch (qual) { case PREV_ROW_QUAL: te.prevEndRow = TabletColumnFamily.decodePrevEndRow(kv.getValue()); te.sawPrevEndRow = true; break; case OLD_PREV_ROW_QUAL: te.oldPrevEndRow = TabletColumnFamily.decodePrevEndRow(kv.getValue()); te.sawOldPrevEndRow = true; break; case SPLIT_RATIO_QUAL: te.splitRatio = Double.parseDouble(val); break; } break; case ServerColumnFamily.STR_NAME: switch (qual) { case DIRECTORY_QUAL: Preconditions.checkArgument(ServerColumnFamily.isValidDirCol(val), "Saw invalid dir name {} {}", key, val); te.dirName = val; break; case TIME_QUAL: te.time = MetadataTime.parse(val); break; case FLUSH_QUAL: te.flush = OptionalLong.of(Long.parseLong(val)); break; case COMPACT_QUAL: te.compact = OptionalLong.of(Long.parseLong(val)); break; } break; case DataFileColumnFamily.STR_NAME: filesBuilder.put(new StoredTabletFile(qual), new DataFileValue(val)); break; case BulkFileColumnFamily.STR_NAME: loadedFilesBuilder.put(new StoredTabletFile(qual), BulkFileColumnFamily.getBulkLoadTid(val)); break; case CurrentLocationColumnFamily.STR_NAME: te.setLocationOnce(val, qual, LocationType.CURRENT); break; case FutureLocationColumnFamily.STR_NAME: te.setLocationOnce(val, qual, LocationType.FUTURE); break; case LastLocationColumnFamily.STR_NAME: te.last = new Location(val, qual, LocationType.LAST); break; case ScanFileColumnFamily.STR_NAME: scansBuilder.add(new StoredTabletFile(qual)); break; case ClonedColumnFamily.STR_NAME: te.cloned = val; break; case LogColumnFamily.STR_NAME: logsBuilder.add(LogEntry.fromMetaWalEntry(kv)); break; default: throw new IllegalStateException("Unexpected family " + fam); } } te.files = filesBuilder.build(); te.loadedFiles = loadedFilesBuilder.build(); te.fetchedCols = fetchedColumns; te.scans = scansBuilder.build(); te.logs = logsBuilder.build(); if (buildKeyValueMap) { te.keyValues = kvBuilder.build(); } return te; } }
TabletMetadata { @VisibleForTesting public static TabletMetadata convertRow(Iterator<Entry<Key,Value>> rowIter, EnumSet<ColumnType> fetchedColumns, boolean buildKeyValueMap) { Objects.requireNonNull(rowIter); TabletMetadata te = new TabletMetadata(); ImmutableSortedMap.Builder<Key,Value> kvBuilder = null; if (buildKeyValueMap) { kvBuilder = ImmutableSortedMap.naturalOrder(); } var filesBuilder = ImmutableMap.<StoredTabletFile,DataFileValue>builder(); var scansBuilder = ImmutableList.<StoredTabletFile>builder(); var logsBuilder = ImmutableList.<LogEntry>builder(); final var loadedFilesBuilder = ImmutableMap.<TabletFile,Long>builder(); ByteSequence row = null; while (rowIter.hasNext()) { final Entry<Key,Value> kv = rowIter.next(); final Key key = kv.getKey(); final String val = kv.getValue().toString(); final String fam = key.getColumnFamilyData().toString(); final String qual = key.getColumnQualifierData().toString(); if (buildKeyValueMap) { kvBuilder.put(key, kv.getValue()); } if (row == null) { row = key.getRowData(); KeyExtent ke = KeyExtent.fromMetaRow(key.getRow()); te.endRow = ke.endRow(); te.tableId = ke.tableId(); } else if (!row.equals(key.getRowData())) { throw new IllegalArgumentException( "Input contains more than one row : " + row + " " + key.getRowData()); } switch (fam.toString()) { case TabletColumnFamily.STR_NAME: switch (qual) { case PREV_ROW_QUAL: te.prevEndRow = TabletColumnFamily.decodePrevEndRow(kv.getValue()); te.sawPrevEndRow = true; break; case OLD_PREV_ROW_QUAL: te.oldPrevEndRow = TabletColumnFamily.decodePrevEndRow(kv.getValue()); te.sawOldPrevEndRow = true; break; case SPLIT_RATIO_QUAL: te.splitRatio = Double.parseDouble(val); break; } break; case ServerColumnFamily.STR_NAME: switch (qual) { case DIRECTORY_QUAL: Preconditions.checkArgument(ServerColumnFamily.isValidDirCol(val), "Saw invalid dir name {} {}", key, val); te.dirName = val; break; case TIME_QUAL: te.time = MetadataTime.parse(val); break; case FLUSH_QUAL: te.flush = OptionalLong.of(Long.parseLong(val)); break; case COMPACT_QUAL: te.compact = OptionalLong.of(Long.parseLong(val)); break; } break; case DataFileColumnFamily.STR_NAME: filesBuilder.put(new StoredTabletFile(qual), new DataFileValue(val)); break; case BulkFileColumnFamily.STR_NAME: loadedFilesBuilder.put(new StoredTabletFile(qual), BulkFileColumnFamily.getBulkLoadTid(val)); break; case CurrentLocationColumnFamily.STR_NAME: te.setLocationOnce(val, qual, LocationType.CURRENT); break; case FutureLocationColumnFamily.STR_NAME: te.setLocationOnce(val, qual, LocationType.FUTURE); break; case LastLocationColumnFamily.STR_NAME: te.last = new Location(val, qual, LocationType.LAST); break; case ScanFileColumnFamily.STR_NAME: scansBuilder.add(new StoredTabletFile(qual)); break; case ClonedColumnFamily.STR_NAME: te.cloned = val; break; case LogColumnFamily.STR_NAME: logsBuilder.add(LogEntry.fromMetaWalEntry(kv)); break; default: throw new IllegalStateException("Unexpected family " + fam); } } te.files = filesBuilder.build(); te.loadedFiles = loadedFilesBuilder.build(); te.fetchedCols = fetchedColumns; te.scans = scansBuilder.build(); te.logs = logsBuilder.build(); if (buildKeyValueMap) { te.keyValues = kvBuilder.build(); } return te; }  }
TabletMetadata { @VisibleForTesting public static TabletMetadata convertRow(Iterator<Entry<Key,Value>> rowIter, EnumSet<ColumnType> fetchedColumns, boolean buildKeyValueMap) { Objects.requireNonNull(rowIter); TabletMetadata te = new TabletMetadata(); ImmutableSortedMap.Builder<Key,Value> kvBuilder = null; if (buildKeyValueMap) { kvBuilder = ImmutableSortedMap.naturalOrder(); } var filesBuilder = ImmutableMap.<StoredTabletFile,DataFileValue>builder(); var scansBuilder = ImmutableList.<StoredTabletFile>builder(); var logsBuilder = ImmutableList.<LogEntry>builder(); final var loadedFilesBuilder = ImmutableMap.<TabletFile,Long>builder(); ByteSequence row = null; while (rowIter.hasNext()) { final Entry<Key,Value> kv = rowIter.next(); final Key key = kv.getKey(); final String val = kv.getValue().toString(); final String fam = key.getColumnFamilyData().toString(); final String qual = key.getColumnQualifierData().toString(); if (buildKeyValueMap) { kvBuilder.put(key, kv.getValue()); } if (row == null) { row = key.getRowData(); KeyExtent ke = KeyExtent.fromMetaRow(key.getRow()); te.endRow = ke.endRow(); te.tableId = ke.tableId(); } else if (!row.equals(key.getRowData())) { throw new IllegalArgumentException( "Input contains more than one row : " + row + " " + key.getRowData()); } switch (fam.toString()) { case TabletColumnFamily.STR_NAME: switch (qual) { case PREV_ROW_QUAL: te.prevEndRow = TabletColumnFamily.decodePrevEndRow(kv.getValue()); te.sawPrevEndRow = true; break; case OLD_PREV_ROW_QUAL: te.oldPrevEndRow = TabletColumnFamily.decodePrevEndRow(kv.getValue()); te.sawOldPrevEndRow = true; break; case SPLIT_RATIO_QUAL: te.splitRatio = Double.parseDouble(val); break; } break; case ServerColumnFamily.STR_NAME: switch (qual) { case DIRECTORY_QUAL: Preconditions.checkArgument(ServerColumnFamily.isValidDirCol(val), "Saw invalid dir name {} {}", key, val); te.dirName = val; break; case TIME_QUAL: te.time = MetadataTime.parse(val); break; case FLUSH_QUAL: te.flush = OptionalLong.of(Long.parseLong(val)); break; case COMPACT_QUAL: te.compact = OptionalLong.of(Long.parseLong(val)); break; } break; case DataFileColumnFamily.STR_NAME: filesBuilder.put(new StoredTabletFile(qual), new DataFileValue(val)); break; case BulkFileColumnFamily.STR_NAME: loadedFilesBuilder.put(new StoredTabletFile(qual), BulkFileColumnFamily.getBulkLoadTid(val)); break; case CurrentLocationColumnFamily.STR_NAME: te.setLocationOnce(val, qual, LocationType.CURRENT); break; case FutureLocationColumnFamily.STR_NAME: te.setLocationOnce(val, qual, LocationType.FUTURE); break; case LastLocationColumnFamily.STR_NAME: te.last = new Location(val, qual, LocationType.LAST); break; case ScanFileColumnFamily.STR_NAME: scansBuilder.add(new StoredTabletFile(qual)); break; case ClonedColumnFamily.STR_NAME: te.cloned = val; break; case LogColumnFamily.STR_NAME: logsBuilder.add(LogEntry.fromMetaWalEntry(kv)); break; default: throw new IllegalStateException("Unexpected family " + fam); } } te.files = filesBuilder.build(); te.loadedFiles = loadedFilesBuilder.build(); te.fetchedCols = fetchedColumns; te.scans = scansBuilder.build(); te.logs = logsBuilder.build(); if (buildKeyValueMap) { te.keyValues = kvBuilder.build(); } return te; }  TableId getTableId(); KeyExtent getExtent(); Text getPrevEndRow(); boolean sawPrevEndRow(); Text getOldPrevEndRow(); boolean sawOldPrevEndRow(); Text getEndRow(); Location getLocation(); boolean hasCurrent(); Map<TabletFile,Long> getLoaded(); Location getLast(); Collection<StoredTabletFile> getFiles(); Map<StoredTabletFile,DataFileValue> getFilesMap(); Collection<LogEntry> getLogs(); List<StoredTabletFile> getScans(); String getDirName(); MetadataTime getTime(); String getCloned(); OptionalLong getFlushId(); OptionalLong getCompactId(); Double getSplitRatio(); SortedMap<Key,Value> getKeyValues(); @VisibleForTesting static TabletMetadata convertRow(Iterator<Entry<Key,Value>> rowIter,
      EnumSet<ColumnType> fetchedColumns, boolean buildKeyValueMap); }
TabletMetadata { @VisibleForTesting public static TabletMetadata convertRow(Iterator<Entry<Key,Value>> rowIter, EnumSet<ColumnType> fetchedColumns, boolean buildKeyValueMap) { Objects.requireNonNull(rowIter); TabletMetadata te = new TabletMetadata(); ImmutableSortedMap.Builder<Key,Value> kvBuilder = null; if (buildKeyValueMap) { kvBuilder = ImmutableSortedMap.naturalOrder(); } var filesBuilder = ImmutableMap.<StoredTabletFile,DataFileValue>builder(); var scansBuilder = ImmutableList.<StoredTabletFile>builder(); var logsBuilder = ImmutableList.<LogEntry>builder(); final var loadedFilesBuilder = ImmutableMap.<TabletFile,Long>builder(); ByteSequence row = null; while (rowIter.hasNext()) { final Entry<Key,Value> kv = rowIter.next(); final Key key = kv.getKey(); final String val = kv.getValue().toString(); final String fam = key.getColumnFamilyData().toString(); final String qual = key.getColumnQualifierData().toString(); if (buildKeyValueMap) { kvBuilder.put(key, kv.getValue()); } if (row == null) { row = key.getRowData(); KeyExtent ke = KeyExtent.fromMetaRow(key.getRow()); te.endRow = ke.endRow(); te.tableId = ke.tableId(); } else if (!row.equals(key.getRowData())) { throw new IllegalArgumentException( "Input contains more than one row : " + row + " " + key.getRowData()); } switch (fam.toString()) { case TabletColumnFamily.STR_NAME: switch (qual) { case PREV_ROW_QUAL: te.prevEndRow = TabletColumnFamily.decodePrevEndRow(kv.getValue()); te.sawPrevEndRow = true; break; case OLD_PREV_ROW_QUAL: te.oldPrevEndRow = TabletColumnFamily.decodePrevEndRow(kv.getValue()); te.sawOldPrevEndRow = true; break; case SPLIT_RATIO_QUAL: te.splitRatio = Double.parseDouble(val); break; } break; case ServerColumnFamily.STR_NAME: switch (qual) { case DIRECTORY_QUAL: Preconditions.checkArgument(ServerColumnFamily.isValidDirCol(val), "Saw invalid dir name {} {}", key, val); te.dirName = val; break; case TIME_QUAL: te.time = MetadataTime.parse(val); break; case FLUSH_QUAL: te.flush = OptionalLong.of(Long.parseLong(val)); break; case COMPACT_QUAL: te.compact = OptionalLong.of(Long.parseLong(val)); break; } break; case DataFileColumnFamily.STR_NAME: filesBuilder.put(new StoredTabletFile(qual), new DataFileValue(val)); break; case BulkFileColumnFamily.STR_NAME: loadedFilesBuilder.put(new StoredTabletFile(qual), BulkFileColumnFamily.getBulkLoadTid(val)); break; case CurrentLocationColumnFamily.STR_NAME: te.setLocationOnce(val, qual, LocationType.CURRENT); break; case FutureLocationColumnFamily.STR_NAME: te.setLocationOnce(val, qual, LocationType.FUTURE); break; case LastLocationColumnFamily.STR_NAME: te.last = new Location(val, qual, LocationType.LAST); break; case ScanFileColumnFamily.STR_NAME: scansBuilder.add(new StoredTabletFile(qual)); break; case ClonedColumnFamily.STR_NAME: te.cloned = val; break; case LogColumnFamily.STR_NAME: logsBuilder.add(LogEntry.fromMetaWalEntry(kv)); break; default: throw new IllegalStateException("Unexpected family " + fam); } } te.files = filesBuilder.build(); te.loadedFiles = loadedFilesBuilder.build(); te.fetchedCols = fetchedColumns; te.scans = scansBuilder.build(); te.logs = logsBuilder.build(); if (buildKeyValueMap) { te.keyValues = kvBuilder.build(); } return te; }  TableId getTableId(); KeyExtent getExtent(); Text getPrevEndRow(); boolean sawPrevEndRow(); Text getOldPrevEndRow(); boolean sawOldPrevEndRow(); Text getEndRow(); Location getLocation(); boolean hasCurrent(); Map<TabletFile,Long> getLoaded(); Location getLast(); Collection<StoredTabletFile> getFiles(); Map<StoredTabletFile,DataFileValue> getFilesMap(); Collection<LogEntry> getLogs(); List<StoredTabletFile> getScans(); String getDirName(); MetadataTime getTime(); String getCloned(); OptionalLong getFlushId(); OptionalLong getCompactId(); Double getSplitRatio(); SortedMap<Key,Value> getKeyValues(); @VisibleForTesting static TabletMetadata convertRow(Iterator<Entry<Key,Value>> rowIter,
      EnumSet<ColumnType> fetchedColumns, boolean buildKeyValueMap);  }