Search in sources :

Example 1 with TxTask

use of com.palantir.atlasdb.transaction.impl.TxTask in project atlasdb by palantir.

the class AtlasDbServiceImpl method abort.

@Override
public void abort(TransactionToken token) {
    RawTransaction tx = transactions.getIfPresent(token);
    if (tx != null) {
        txManager.finishRunTaskWithLockThrowOnConflict(tx, (TxTask) transaction -> {
            transaction.abort();
            return null;
        });
        transactions.invalidate(token);
    }
}
Also used : TableCellVal(com.palantir.atlasdb.api.TableCellVal) TableRowResult(com.palantir.atlasdb.api.TableRowResult) ColumnMetadataDescription(com.palantir.atlasdb.table.description.ColumnMetadataDescription) ConflictHandler(com.palantir.atlasdb.transaction.api.ConflictHandler) BatchingVisitable(com.palantir.common.base.BatchingVisitable) ColumnValueDescription(com.palantir.atlasdb.table.description.ColumnValueDescription) Inject(javax.inject.Inject) RangeToken(com.palantir.atlasdb.api.RangeToken) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) SerializableTransactionManager(com.palantir.atlasdb.transaction.impl.SerializableTransactionManager) RuntimeTransactionTask(com.palantir.atlasdb.transaction.api.RuntimeTransactionTask) BatchingVisitables(com.palantir.common.base.BatchingVisitables) TableRowSelection(com.palantir.atlasdb.api.TableRowSelection) TableRange(com.palantir.atlasdb.api.TableRange) TableMetadataPersistence(com.palantir.atlasdb.protos.generated.TableMetadataPersistence) TableMetadata(com.palantir.atlasdb.table.description.TableMetadata) ImmutableSet(com.google.common.collect.ImmutableSet) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Collection(java.util.Collection) NameComponentDescription(com.palantir.atlasdb.table.description.NameComponentDescription) Set(java.util.Set) PreCommitConditions(com.palantir.atlasdb.transaction.impl.PreCommitConditions) UUID(java.util.UUID) RawTransaction(com.palantir.atlasdb.transaction.impl.RawTransaction) Collectors(java.util.stream.Collectors) TableCell(com.palantir.atlasdb.api.TableCell) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) TimeUnit(java.util.concurrent.TimeUnit) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) List(java.util.List) TxTask(com.palantir.atlasdb.transaction.impl.TxTask) TransactionToken(com.palantir.atlasdb.api.TransactionToken) ValueType(com.palantir.atlasdb.table.description.ValueType) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) AtlasDbService(com.palantir.atlasdb.api.AtlasDbService) Preconditions(com.google.common.base.Preconditions) NameMetadataDescription(com.palantir.atlasdb.table.description.NameMetadataDescription) CacheBuilder(com.google.common.cache.CacheBuilder) Cache(com.google.common.cache.Cache) DynamicColumnDescription(com.palantir.atlasdb.table.description.DynamicColumnDescription) RawTransaction(com.palantir.atlasdb.transaction.impl.RawTransaction)

Example 2 with TxTask

use of com.palantir.atlasdb.transaction.impl.TxTask in project atlasdb by palantir.

the class AtlasDbServiceImpl method commit.

@Override
public void commit(TransactionToken token) {
    RawTransaction tx = transactions.getIfPresent(token);
    if (tx != null) {
        txManager.finishRunTaskWithLockThrowOnConflict(tx, (TxTask) transaction -> null);
        transactions.invalidate(token);
    }
}
Also used : TableCellVal(com.palantir.atlasdb.api.TableCellVal) TableRowResult(com.palantir.atlasdb.api.TableRowResult) ColumnMetadataDescription(com.palantir.atlasdb.table.description.ColumnMetadataDescription) ConflictHandler(com.palantir.atlasdb.transaction.api.ConflictHandler) BatchingVisitable(com.palantir.common.base.BatchingVisitable) ColumnValueDescription(com.palantir.atlasdb.table.description.ColumnValueDescription) Inject(javax.inject.Inject) RangeToken(com.palantir.atlasdb.api.RangeToken) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) SerializableTransactionManager(com.palantir.atlasdb.transaction.impl.SerializableTransactionManager) RuntimeTransactionTask(com.palantir.atlasdb.transaction.api.RuntimeTransactionTask) BatchingVisitables(com.palantir.common.base.BatchingVisitables) TableRowSelection(com.palantir.atlasdb.api.TableRowSelection) TableRange(com.palantir.atlasdb.api.TableRange) TableMetadataPersistence(com.palantir.atlasdb.protos.generated.TableMetadataPersistence) TableMetadata(com.palantir.atlasdb.table.description.TableMetadata) ImmutableSet(com.google.common.collect.ImmutableSet) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Collection(java.util.Collection) NameComponentDescription(com.palantir.atlasdb.table.description.NameComponentDescription) Set(java.util.Set) PreCommitConditions(com.palantir.atlasdb.transaction.impl.PreCommitConditions) UUID(java.util.UUID) RawTransaction(com.palantir.atlasdb.transaction.impl.RawTransaction) Collectors(java.util.stream.Collectors) TableCell(com.palantir.atlasdb.api.TableCell) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) TimeUnit(java.util.concurrent.TimeUnit) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) List(java.util.List) TxTask(com.palantir.atlasdb.transaction.impl.TxTask) TransactionToken(com.palantir.atlasdb.api.TransactionToken) ValueType(com.palantir.atlasdb.table.description.ValueType) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) AtlasDbService(com.palantir.atlasdb.api.AtlasDbService) Preconditions(com.google.common.base.Preconditions) NameMetadataDescription(com.palantir.atlasdb.table.description.NameMetadataDescription) CacheBuilder(com.google.common.cache.CacheBuilder) Cache(com.google.common.cache.Cache) DynamicColumnDescription(com.palantir.atlasdb.table.description.DynamicColumnDescription) RawTransaction(com.palantir.atlasdb.transaction.impl.RawTransaction)

Example 3 with TxTask

use of com.palantir.atlasdb.transaction.impl.TxTask in project atlasdb by palantir.

the class SweepCommand method execute.

@Override
public int execute(final AtlasDbServices services) {
    SweepTaskRunner sweepRunner = services.getSweepTaskRunner();
    if (!((namespace != null) ^ (table != null) ^ sweepAllTables)) {
        printer.error("Specify one of --namespace, --table, or --all options.");
        return 1;
    }
    if ((namespace != null) && (row != null)) {
        printer.error("Cannot specify a start row (" + row + ") when sweeping multiple tables (in namespace " + namespace + ")");
        return 1;
    }
    Map<TableReference, byte[]> tableToStartRow = Maps.newHashMap();
    if (table != null) {
        TableReference tableToSweep = TableReference.createUnsafe(table);
        if (!services.getKeyValueService().getAllTableNames().contains(tableToSweep)) {
            printer.info("The table {} passed in to sweep does not exist", LoggingArgs.tableRef(tableToSweep));
            return 1;
        }
        byte[] startRow = PtBytes.EMPTY_BYTE_ARRAY;
        if (row != null) {
            startRow = decodeStartRow(row);
        }
        tableToStartRow.put(tableToSweep, startRow);
    } else if (namespace != null) {
        Set<TableReference> tablesInNamespace = services.getKeyValueService().getAllTableNames().stream().filter(tableRef -> tableRef.getNamespace().getName().equals(namespace)).collect(Collectors.toSet());
        for (TableReference tableInNamespace : tablesInNamespace) {
            tableToStartRow.put(tableInNamespace, new byte[0]);
        }
    } else if (sweepAllTables) {
        tableToStartRow.putAll(Maps.asMap(Sets.difference(services.getKeyValueService().getAllTableNames(), AtlasDbConstants.hiddenTables), Functions.constant(new byte[0])));
    }
    SweepBatchConfig batchConfig = getSweepBatchConfig();
    for (Map.Entry<TableReference, byte[]> entry : tableToStartRow.entrySet()) {
        final TableReference tableToSweep = entry.getKey();
        SweepResults accumulatedResults = SweepResults.createEmptySweepResult(Optional.of(entry.getValue()));
        while (accumulatedResults.getNextStartRow().isPresent()) {
            SweepResults newResults = dryRun ? sweepRunner.dryRun(tableToSweep, batchConfig, accumulatedResults.getNextStartRow().get()) : sweepRunner.run(tableToSweep, batchConfig, accumulatedResults.getNextStartRow().get());
            accumulatedResults = accumulatedResults.accumulateWith(newResults);
            printer.info("{} Swept from {} to {} in table {} in {} ms, examined {} cell values," + " deleted {} stale versions of those cells. Time elapsed since started sweeping:" + " {} ms. Total time sweeping this table: {} ms.", SafeArg.of("isDryRun", dryRun ? "[DRY RUN]" : ""), UnsafeArg.of("startRow", encodeStartRow(accumulatedResults.getNextStartRow())), UnsafeArg.of("exclusiveEndRow", encodeEndRow(newResults.getNextStartRow())), LoggingArgs.tableRef(tableToSweep), SafeArg.of("time taken millis", newResults.getTimeInMillis()), SafeArg.of("cellTs pairs examined", newResults.getCellTsPairsExamined()), SafeArg.of("cellTs pairs deleted", newResults.getStaleValuesDeleted()), SafeArg.of("time elapsed", accumulatedResults.getTimeElapsedSinceStartedSweeping()), SafeArg.of("time sweeping", accumulatedResults.getTimeInMillis()));
            maybeSleep();
        }
        SweepResults finalAccumulatedResults = accumulatedResults;
        if (!dryRun) {
            services.getTransactionManager().runTaskWithRetry((TxTask) t -> {
                SweepPriorityTable priorityTable = SweepTableFactory.of().getSweepPriorityTable(t);
                SweepPriorityTable.SweepPriorityRow row1 = SweepPriorityTable.SweepPriorityRow.of(tableToSweep.getQualifiedName());
                priorityTable.putWriteCount(row1, 0L);
                priorityTable.putCellsExamined(row1, finalAccumulatedResults.getCellTsPairsExamined());
                priorityTable.putCellsDeleted(row1, finalAccumulatedResults.getStaleValuesDeleted());
                priorityTable.putLastSweepTime(row1, System.currentTimeMillis());
                return null;
            });
        }
        printer.info("{} Finished sweeping {}, examined {} cell values, deleted {} stale versions of those cells.", SafeArg.of("isDryRun", dryRun ? "[DRY RUN]" : ""), LoggingArgs.tableRef(tableToSweep), SafeArg.of("cellTs pairs examined", finalAccumulatedResults.getCellTsPairsExamined()), SafeArg.of("cellTs pairs deleted", finalAccumulatedResults.getStaleValuesDeleted()));
        if (!dryRun && finalAccumulatedResults.getStaleValuesDeleted() > 0) {
            Stopwatch watch = Stopwatch.createStarted();
            services.getKeyValueService().compactInternally(tableToSweep);
            printer.info("Finished performing compactInternally on {} in {} ms.", LoggingArgs.tableRef(tableToSweep), SafeArg.of("time taken", watch.elapsed(TimeUnit.MILLISECONDS)));
        }
    }
    return 0;
}
Also used : Arrays(java.util.Arrays) OutputPrinter(com.palantir.atlasdb.cli.output.OutputPrinter) Stopwatch(com.google.common.base.Stopwatch) Throwables(com.palantir.common.base.Throwables) LoggerFactory(org.slf4j.LoggerFactory) PtBytes(com.palantir.atlasdb.encoding.PtBytes) SafeArg(com.palantir.logsafe.SafeArg) ImmutableSweepBatchConfig(com.palantir.atlasdb.sweep.ImmutableSweepBatchConfig) Option(io.airlift.airline.Option) Map(java.util.Map) LoggingArgs(com.palantir.atlasdb.logging.LoggingArgs) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) SweepTaskRunner(com.palantir.atlasdb.sweep.SweepTaskRunner) Nullable(javax.annotation.Nullable) AtlasDbConstants(com.palantir.atlasdb.AtlasDbConstants) Functions(com.google.common.base.Functions) BaseEncoding(com.google.common.io.BaseEncoding) Set(java.util.Set) SweepResults(com.palantir.atlasdb.keyvalue.api.SweepResults) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) SweepPriorityTable(com.palantir.atlasdb.schema.generated.SweepPriorityTable) TimeUnit(java.util.concurrent.TimeUnit) SweepBatchConfig(com.palantir.atlasdb.sweep.SweepBatchConfig) Command(io.airlift.airline.Command) SweepTableFactory(com.palantir.atlasdb.schema.generated.SweepTableFactory) TxTask(com.palantir.atlasdb.transaction.impl.TxTask) UnsafeArg(com.palantir.logsafe.UnsafeArg) Optional(java.util.Optional) AtlasDbServices(com.palantir.atlasdb.services.AtlasDbServices) SweepResults(com.palantir.atlasdb.keyvalue.api.SweepResults) Set(java.util.Set) Stopwatch(com.google.common.base.Stopwatch) SweepTaskRunner(com.palantir.atlasdb.sweep.SweepTaskRunner) ImmutableSweepBatchConfig(com.palantir.atlasdb.sweep.ImmutableSweepBatchConfig) SweepBatchConfig(com.palantir.atlasdb.sweep.SweepBatchConfig) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) SweepPriorityTable(com.palantir.atlasdb.schema.generated.SweepPriorityTable) Map(java.util.Map)

Aggregations

TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)3 TxTask (com.palantir.atlasdb.transaction.impl.TxTask)3 Map (java.util.Map)3 Set (java.util.Set)3 TimeUnit (java.util.concurrent.TimeUnit)3 Collectors (java.util.stream.Collectors)3 Preconditions (com.google.common.base.Preconditions)2 Cache (com.google.common.cache.Cache)2 CacheBuilder (com.google.common.cache.CacheBuilder)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 AtlasDbService (com.palantir.atlasdb.api.AtlasDbService)2 RangeToken (com.palantir.atlasdb.api.RangeToken)2 TableCell (com.palantir.atlasdb.api.TableCell)2 TableCellVal (com.palantir.atlasdb.api.TableCellVal)2 TableRange (com.palantir.atlasdb.api.TableRange)2 TableRowResult (com.palantir.atlasdb.api.TableRowResult)2 TableRowSelection (com.palantir.atlasdb.api.TableRowSelection)2 TransactionToken (com.palantir.atlasdb.api.TransactionToken)2 Cell (com.palantir.atlasdb.keyvalue.api.Cell)2