use of org.apache.accumulo.core.clientImpl.ClientContext in project accumulo by apache.
the class InputConfigurator method binOffline.
public static Map<String, Map<KeyExtent, List<Range>>> binOffline(TableId tableId, List<Range> ranges, ClientContext context) throws AccumuloException, TableNotFoundException {
Map<String, Map<KeyExtent, List<Range>>> binnedRanges = new HashMap<>();
if (context.getTableState(tableId) != TableState.OFFLINE) {
context.clearTableListCache();
if (context.getTableState(tableId) != TableState.OFFLINE) {
throw new AccumuloException("Table is online tableId:" + tableId + " cannot scan table in offline mode ");
}
}
for (Range range : ranges) {
Text startRow;
if (range.getStartKey() != null)
startRow = range.getStartKey().getRow();
else
startRow = new Text();
Range metadataRange = new Range(new KeyExtent(tableId, startRow, null).toMetaRow(), true, null, false);
Scanner scanner = context.createScanner(MetadataTable.NAME, Authorizations.EMPTY);
TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
scanner.fetchColumnFamily(LastLocationColumnFamily.NAME);
scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
scanner.fetchColumnFamily(FutureLocationColumnFamily.NAME);
scanner.setRange(metadataRange);
RowIterator rowIter = new RowIterator(scanner);
KeyExtent lastExtent = null;
while (rowIter.hasNext()) {
Iterator<Map.Entry<Key, Value>> row = rowIter.next();
String last = "";
KeyExtent extent = null;
String location = null;
while (row.hasNext()) {
Map.Entry<Key, Value> entry = row.next();
Key key = entry.getKey();
if (key.getColumnFamily().equals(LastLocationColumnFamily.NAME)) {
last = entry.getValue().toString();
}
if (key.getColumnFamily().equals(CurrentLocationColumnFamily.NAME) || key.getColumnFamily().equals(FutureLocationColumnFamily.NAME)) {
location = entry.getValue().toString();
}
if (TabletColumnFamily.PREV_ROW_COLUMN.hasColumns(key)) {
extent = KeyExtent.fromMetaPrevRow(entry);
}
}
if (location != null)
return null;
if (!extent.tableId().equals(tableId)) {
throw new AccumuloException("Saw unexpected table Id " + tableId + " " + extent);
}
if (lastExtent != null && !extent.isPreviousExtent(lastExtent)) {
throw new AccumuloException(" " + lastExtent + " is not previous extent " + extent);
}
binnedRanges.computeIfAbsent(last, k -> new HashMap<>()).computeIfAbsent(extent, k -> new ArrayList<>()).add(range);
if (extent.endRow() == null || range.afterEndKey(new Key(extent.endRow()).followingKey(PartialKey.ROW))) {
break;
}
lastExtent = extent;
}
}
return binnedRanges;
}
use of org.apache.accumulo.core.clientImpl.ClientContext in project accumulo by apache.
the class Merge method getSizeIterator.
protected Iterator<Size> getSizeIterator(AccumuloClient client, String tablename, Text start, Text end) throws MergeException {
// open up metadata, walk through the tablets.
TableId tableId;
TabletsMetadata tablets;
try {
ClientContext context = (ClientContext) client;
tableId = context.getTableId(tablename);
tablets = TabletsMetadata.builder(context).scanMetadataTable().overRange(new KeyExtent(tableId, end, start).toMetaRange()).fetch(FILES, PREV_ROW).build();
} catch (Exception e) {
throw new MergeException(e);
}
return tablets.stream().map(tm -> {
long size = tm.getFilesMap().values().stream().mapToLong(DataFileValue::getSize).sum();
return new Size(tm.getExtent(), size);
}).iterator();
}
use of org.apache.accumulo.core.clientImpl.ClientContext in project accumulo by apache.
the class ReplicationTableUtilTest method properPathInRow.
@Test
public void properPathInRow() throws Exception {
Writer writer = EasyMock.createNiceMock(Writer.class);
writer.update(EasyMock.anyObject(Mutation.class));
final List<Mutation> mutations = new ArrayList<>();
// Mock a Writer to just add the mutation to a list
EasyMock.expectLastCall().andAnswer(() -> {
mutations.add(((Mutation) EasyMock.getCurrentArguments()[0]));
return null;
});
EasyMock.replay(writer);
Credentials creds = new Credentials("root", new PasswordToken(""));
ClientContext context = EasyMock.createMock(ClientContext.class);
EasyMock.expect(context.getCredentials()).andReturn(creds).anyTimes();
EasyMock.replay(context);
// Magic hook to create a Writer
ReplicationTableUtil.addWriter(creds, writer);
// Example file seen coming out of LogEntry
UUID uuid = UUID.randomUUID();
String myFile = "file:////home/user/accumulo/wal/server+port/" + uuid;
long createdTime = System.currentTimeMillis();
ReplicationTableUtil.updateFiles(context, new KeyExtent(TableId.of("1"), null, null), myFile, StatusUtil.fileCreated(createdTime));
verify(writer);
assertEquals(1, mutations.size());
Mutation m = mutations.get(0);
assertEquals(ReplicationSection.getRowPrefix() + "file:/home/user/accumulo/wal/server+port/" + uuid, new Text(m.getRow()).toString());
List<ColumnUpdate> updates = m.getUpdates();
assertEquals(1, updates.size());
ColumnUpdate update = updates.get(0);
assertEquals(ReplicationSection.COLF, new Text(update.getColumnFamily()));
assertEquals("1", new Text(update.getColumnQualifier()).toString());
assertEquals(StatusUtil.fileCreatedValue(createdTime), new Value(update.getValue()));
}
Aggregations