public static TabletLocationState createTabletLocationState(Key k, Value v) throws IOException, BadLocationStateException { final SortedMap<Key, Value> decodedRow = WholeRowIterator.decodeRow(k, v); KeyExtent extent = null; TServerInstance future = null; TServerInstance current = null; TServerInstance last = null; long lastTimestamp = 0; List<Collection<String>> walogs = new ArrayList<Collection<String>>(); boolean chopped = false; for (Entry<Key, Value> entry : decodedRow.entrySet()) { Key key = entry.getKey(); Text row = key.getRow(); Text cf = key.getColumnFamily(); Text cq = key.getColumnQualifier(); if (cf.compareTo(TabletsSection.FutureLocationColumnFamily.NAME) == 0) { TServerInstance location = new TServerInstance(entry.getValue(), cq); if (future != null) { throw new BadLocationStateException( "found two assignments for the same extent " + key.getRow() + ": " + future + " and " + location); } future = location; } else if (cf.compareTo(TabletsSection.CurrentLocationColumnFamily.NAME) == 0) { TServerInstance location = new TServerInstance(entry.getValue(), cq); if (current != null) { throw new BadLocationStateException( "found two locations for the same extent " + key.getRow() + ": " + current + " and " + location); } current = location; } else if (cf.compareTo(LogColumnFamily.NAME) == 0) { String[] split = entry.getValue().toString().split("\\|")[0].split(";"); walogs.add(Arrays.asList(split)); } else if (cf.compareTo(TabletsSection.LastLocationColumnFamily.NAME) == 0) { if (lastTimestamp < entry.getKey().getTimestamp()) last = new TServerInstance(entry.getValue(), cq); } else if (cf.compareTo(ChoppedColumnFamily.NAME) == 0) { chopped = true; } else if (TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.equals(cf, cq)) { extent = new KeyExtent(row, entry.getValue()); } } if (extent == null) { log.warn("No prev-row for key extent: " + decodedRow); return null; } return new TabletLocationState(extent, future, current, last, walogs, chopped); }
private static Scanner createCloneScanner(String tableId, Connector conn) throws TableNotFoundException { Scanner mscanner = new IsolatedScanner(conn.createScanner(MetadataTable.NAME, Authorizations.EMPTY)); mscanner.setRange(new KeyExtent(new Text(tableId), null, null).toMetadataRange()); mscanner.fetchColumnFamily(DataFileColumnFamily.NAME); mscanner.fetchColumnFamily(TabletsSection.CurrentLocationColumnFamily.NAME); mscanner.fetchColumnFamily(TabletsSection.LastLocationColumnFamily.NAME); mscanner.fetchColumnFamily(ClonedColumnFamily.NAME); TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.fetch(mscanner); TabletsSection.ServerColumnFamily.TIME_COLUMN.fetch(mscanner); return mscanner; }
public static void configureScanner(ScannerBase scanner, CurrentState state) { TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner); scanner.fetchColumnFamily(TabletsSection.CurrentLocationColumnFamily.NAME); scanner.fetchColumnFamily(TabletsSection.FutureLocationColumnFamily.NAME); scanner.fetchColumnFamily(TabletsSection.LastLocationColumnFamily.NAME); scanner.fetchColumnFamily(LogColumnFamily.NAME); scanner.fetchColumnFamily(ChoppedColumnFamily.NAME); scanner.addScanIterator(new IteratorSetting(1000, "wholeRows", WholeRowIterator.class)); IteratorSetting tabletChange = new IteratorSetting(1001, "tabletChange", TabletStateChangeIterator.class); if (state != null) { TabletStateChangeIterator.setCurrentServers(tabletChange, state.onlineTabletServers()); TabletStateChangeIterator.setOnlineTables(tabletChange, state.onlineTables()); TabletStateChangeIterator.setMerges(tabletChange, state.merges()); } scanner.addScanIterator(tabletChange); }