use of org.apache.accumulo.core.tabletserver.log.LogEntry in project accumulo by apache.
the class MetadataTableUtil method getLogEntries.
public static List<LogEntry> getLogEntries(ClientContext context, KeyExtent extent) throws IOException, KeeperException, InterruptedException {
log.info("Scanning logging entries for {}", extent);
ArrayList<LogEntry> result = new ArrayList<>();
if (extent.equals(RootTable.EXTENT)) {
log.info("Getting logs for root tablet from zookeeper");
getRootLogEntries(result);
} else {
log.info("Scanning metadata for logs used for tablet {}", extent);
Scanner scanner = getTabletLogScanner(context, extent);
Text pattern = extent.getMetadataEntry();
for (Entry<Key, Value> entry : scanner) {
Text row = entry.getKey().getRow();
if (entry.getKey().getColumnFamily().equals(LogColumnFamily.NAME)) {
if (row.equals(pattern)) {
result.add(LogEntry.fromKeyValue(entry.getKey(), entry.getValue()));
}
}
}
}
log.info("Returning logs {} for extent {}", result, extent);
return result;
}
use of org.apache.accumulo.core.tabletserver.log.LogEntry in project accumulo by apache.
the class MissingWalHeaderCompletesRecoveryIT method testEmptyWalRecoveryCompletes.
@Test
public void testEmptyWalRecoveryCompletes() throws Exception {
Connector conn = getConnector();
MiniAccumuloClusterImpl cluster = getCluster();
FileSystem fs = cluster.getFileSystem();
// Fake out something that looks like host:port, it's irrelevant
String fakeServer = "127.0.0.1:12345";
File walogs = new File(cluster.getConfig().getAccumuloDir(), ServerConstants.WAL_DIR);
File walogServerDir = new File(walogs, fakeServer.replace(':', '+'));
File emptyWalog = new File(walogServerDir, UUID.randomUUID().toString());
log.info("Created empty WAL at {}", emptyWalog.toURI());
fs.create(new Path(emptyWalog.toURI())).close();
Assert.assertTrue("root user did not have write permission to metadata table", conn.securityOperations().hasTablePermission("root", MetadataTable.NAME, TablePermission.WRITE));
String tableName = getUniqueNames(1)[0];
conn.tableOperations().create(tableName);
Table.ID tableId = Table.ID.of(conn.tableOperations().tableIdMap().get(tableName));
Assert.assertNotNull("Table ID was null", tableId);
LogEntry logEntry = new LogEntry(new KeyExtent(tableId, null, null), 0, "127.0.0.1:12345", emptyWalog.toURI().toString());
log.info("Taking {} offline", tableName);
conn.tableOperations().offline(tableName, true);
log.info("{} is offline", tableName);
Text row = MetadataSchema.TabletsSection.getRow(tableId, null);
Mutation m = new Mutation(row);
m.put(logEntry.getColumnFamily(), logEntry.getColumnQualifier(), logEntry.getValue());
BatchWriter bw = conn.createBatchWriter(MetadataTable.NAME, new BatchWriterConfig());
bw.addMutation(m);
bw.close();
log.info("Bringing {} online", tableName);
conn.tableOperations().online(tableName, true);
log.info("{} is online", tableName);
// otherwise the tablet will never come online and we won't be able to read it.
try (Scanner s = conn.createScanner(tableName, Authorizations.EMPTY)) {
Assert.assertEquals(0, Iterables.size(s));
}
}
use of org.apache.accumulo.core.tabletserver.log.LogEntry in project accumulo by apache.
the class MissingWalHeaderCompletesRecoveryIT method testPartialHeaderWalRecoveryCompletes.
@Test
public void testPartialHeaderWalRecoveryCompletes() throws Exception {
Connector conn = getConnector();
MiniAccumuloClusterImpl cluster = getCluster();
FileSystem fs = getCluster().getFileSystem();
// Fake out something that looks like host:port, it's irrelevant
String fakeServer = "127.0.0.1:12345";
File walogs = new File(cluster.getConfig().getAccumuloDir(), ServerConstants.WAL_DIR);
File walogServerDir = new File(walogs, fakeServer.replace(':', '+'));
File partialHeaderWalog = new File(walogServerDir, UUID.randomUUID().toString());
log.info("Created WAL with malformed header at {}", partialHeaderWalog.toURI());
// Write half of the header
FSDataOutputStream wal = fs.create(new Path(partialHeaderWalog.toURI()));
wal.write(DfsLogger.LOG_FILE_HEADER_V3.getBytes(UTF_8), 0, DfsLogger.LOG_FILE_HEADER_V3.length() / 2);
wal.close();
Assert.assertTrue("root user did not have write permission to metadata table", conn.securityOperations().hasTablePermission("root", MetadataTable.NAME, TablePermission.WRITE));
String tableName = getUniqueNames(1)[0];
conn.tableOperations().create(tableName);
Table.ID tableId = Table.ID.of(conn.tableOperations().tableIdMap().get(tableName));
Assert.assertNotNull("Table ID was null", tableId);
LogEntry logEntry = new LogEntry(null, 0, "127.0.0.1:12345", partialHeaderWalog.toURI().toString());
log.info("Taking {} offline", tableName);
conn.tableOperations().offline(tableName, true);
log.info("{} is offline", tableName);
Text row = MetadataSchema.TabletsSection.getRow(tableId, null);
Mutation m = new Mutation(row);
m.put(logEntry.getColumnFamily(), logEntry.getColumnQualifier(), logEntry.getValue());
BatchWriter bw = conn.createBatchWriter(MetadataTable.NAME, new BatchWriterConfig());
bw.addMutation(m);
bw.close();
log.info("Bringing {} online", tableName);
conn.tableOperations().online(tableName, true);
log.info("{} is online", tableName);
// otherwise the tablet will never come online and we won't be able to read it.
try (Scanner s = conn.createScanner(tableName, Authorizations.EMPTY)) {
Assert.assertEquals(0, Iterables.size(s));
}
}
use of org.apache.accumulo.core.tabletserver.log.LogEntry in project accumulo by apache.
the class ZooTabletStateStore method iterator.
@Override
public ClosableIterator<TabletLocationState> iterator() {
return new ClosableIterator<TabletLocationState>() {
boolean finished = false;
@Override
public boolean hasNext() {
return !finished;
}
@Override
public TabletLocationState next() {
finished = true;
try {
byte[] future = store.get(RootTable.ZROOT_TABLET_FUTURE_LOCATION);
byte[] current = store.get(RootTable.ZROOT_TABLET_LOCATION);
byte[] last = store.get(RootTable.ZROOT_TABLET_LAST_LOCATION);
TServerInstance currentSession = null;
TServerInstance futureSession = null;
TServerInstance lastSession = null;
if (future != null)
futureSession = parse(future);
if (last != null)
lastSession = parse(last);
if (current != null) {
currentSession = parse(current);
futureSession = null;
}
List<Collection<String>> logs = new ArrayList<>();
for (String entry : store.getChildren(RootTable.ZROOT_TABLET_WALOGS)) {
byte[] logInfo = store.get(RootTable.ZROOT_TABLET_WALOGS + "/" + entry);
if (logInfo != null) {
LogEntry logEntry = LogEntry.fromBytes(logInfo);
logs.add(Collections.singleton(logEntry.filename));
log.debug("root tablet log {}", logEntry.filename);
}
}
TabletLocationState result = new TabletLocationState(RootTable.EXTENT, futureSession, currentSession, lastSession, null, logs, false);
log.debug("Returning root tablet state: {}", result);
return result;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
@Override
public void remove() {
throw new NotImplementedException();
}
@Override
public void close() {
}
};
}
use of org.apache.accumulo.core.tabletserver.log.LogEntry in project accumulo by apache.
the class MetaDataStateStore method suspend.
@Override
public void suspend(Collection<TabletLocationState> tablets, Map<TServerInstance, List<Path>> logsForDeadServers, long suspensionTimestamp) throws DistributedStoreException {
BatchWriter writer = createBatchWriter();
try {
for (TabletLocationState tls : tablets) {
Mutation m = new Mutation(tls.extent.getMetadataEntry());
if (tls.current != null) {
tls.current.clearLocation(m);
if (logsForDeadServers != null) {
List<Path> logs = logsForDeadServers.get(tls.current);
if (logs != null) {
for (Path log : logs) {
LogEntry entry = new LogEntry(tls.extent, 0, tls.current.hostPort(), log.toString());
m.put(entry.getColumnFamily(), entry.getColumnQualifier(), entry.getValue());
}
}
}
if (suspensionTimestamp >= 0) {
SuspendingTServer suspender = new SuspendingTServer(tls.current.getLocation(), suspensionTimestamp);
suspender.setSuspension(m);
}
}
if (tls.suspend != null && suspensionTimestamp < 0) {
SuspendingTServer.clearSuspension(m);
}
if (tls.future != null) {
tls.future.clearFutureLocation(m);
}
writer.addMutation(m);
}
} catch (Exception ex) {
throw new DistributedStoreException(ex);
} finally {
try {
writer.close();
} catch (MutationsRejectedException e) {
throw new DistributedStoreException(e);
}
}
}
Aggregations