Search in sources :

Example 6 with LogEntry

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;
}
Also used : IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) Scanner(org.apache.accumulo.core.client.Scanner) ArrayList(java.util.ArrayList) Value(org.apache.accumulo.core.data.Value) DataFileValue(org.apache.accumulo.core.metadata.schema.DataFileValue) Text(org.apache.hadoop.io.Text) LogEntry(org.apache.accumulo.core.tabletserver.log.LogEntry) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey)

Example 7 with LogEntry

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));
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) Table(org.apache.accumulo.core.client.impl.Table) Text(org.apache.hadoop.io.Text) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) FileSystem(org.apache.hadoop.fs.FileSystem) RawLocalFileSystem(org.apache.hadoop.fs.RawLocalFileSystem) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) Mutation(org.apache.accumulo.core.data.Mutation) BatchWriter(org.apache.accumulo.core.client.BatchWriter) MiniAccumuloClusterImpl(org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl) File(java.io.File) LogEntry(org.apache.accumulo.core.tabletserver.log.LogEntry) Test(org.junit.Test)

Example 8 with LogEntry

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));
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) Table(org.apache.accumulo.core.client.impl.Table) Text(org.apache.hadoop.io.Text) FileSystem(org.apache.hadoop.fs.FileSystem) RawLocalFileSystem(org.apache.hadoop.fs.RawLocalFileSystem) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) Mutation(org.apache.accumulo.core.data.Mutation) BatchWriter(org.apache.accumulo.core.client.BatchWriter) MiniAccumuloClusterImpl(org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl) File(java.io.File) LogEntry(org.apache.accumulo.core.tabletserver.log.LogEntry) Test(org.junit.Test)

Example 9 with LogEntry

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() {
        }
    };
}
Also used : NotImplementedException(org.apache.commons.lang.NotImplementedException) ArrayList(java.util.ArrayList) Collection(java.util.Collection) LogEntry(org.apache.accumulo.core.tabletserver.log.LogEntry) IOException(java.io.IOException) NotImplementedException(org.apache.commons.lang.NotImplementedException)

Example 10 with LogEntry

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);
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) LogEntry(org.apache.accumulo.core.tabletserver.log.LogEntry) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Aggregations

LogEntry (org.apache.accumulo.core.tabletserver.log.LogEntry)19 Path (org.apache.hadoop.fs.Path)10 ArrayList (java.util.ArrayList)7 Mutation (org.apache.accumulo.core.data.Mutation)7 Value (org.apache.accumulo.core.data.Value)7 Text (org.apache.hadoop.io.Text)7 Scanner (org.apache.accumulo.core.client.Scanner)6 Key (org.apache.accumulo.core.data.Key)6 MetadataTable (org.apache.accumulo.core.metadata.MetadataTable)6 BatchWriter (org.apache.accumulo.core.client.BatchWriter)5 Table (org.apache.accumulo.core.client.impl.Table)5 Test (org.junit.Test)5 IOException (java.io.IOException)4 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)4 Connector (org.apache.accumulo.core.client.Connector)4 DataFileValue (org.apache.accumulo.core.metadata.schema.DataFileValue)4 KeyExtent (org.apache.accumulo.core.data.impl.KeyExtent)3 ReplicationTable (org.apache.accumulo.core.replication.ReplicationTable)3 Status (org.apache.accumulo.server.replication.proto.Replication.Status)3 File (java.io.File)2