/** * We must not drop and recreate atomic tables or any of the tables that should specifically be skipped. This is * because large internal product uses a {@link com.palantir.atlasdb.keyvalue.impl.TableSplittingKeyValueService} * that delegates all interactions with these tables to the source KVS as the target KVS, so dropping them would * cause us to drop them in the source KVS. */ public static Set<TableReference> getCreatableTables(KeyValueService kvs, Set<TableReference> skipTables) { Set<TableReference> tableNames = Sets.newHashSet(kvs.getAllTableNames()); tableNames.removeAll(AtlasDbConstants.ATOMIC_TABLES); tableNames.removeAll(skipTables); return tableNames; }
private static Set<TableReference> getExistingTablesAlsoPresentInSchema(Schema schema, KeyValueService kvs) { Set<TableReference> allTables = kvs.getAllTableNames(); Set<TableReference> schemaFullTableNames = Sets.newHashSet(); schemaFullTableNames.addAll(schema.getIndexDefinitions().keySet()); schemaFullTableNames.addAll(schema.getTableDefinitions().keySet()); return schemaFullTableNames.stream().filter(allTables::contains).collect(Collectors.toSet()); }
@Override public void removeTable(TableReference tableRef) { Cell key = Cell.create(getBytesForTableRef(tableRef), AtlasDbConstants.NAMESPACE_SHORT_COLUMN_BYTES); if (kv.getAllTableNames().contains(AtlasDbConstants.NAMESPACE_TABLE)) { kv.delete(AtlasDbConstants.NAMESPACE_TABLE, ImmutableMultimap.of(key, 0L)); } // Need to invalidate the table ref in case we end up re-creating the same table // again. Frequently when we drop one table we end up dropping a bunch of tables, // so just invalidate everything. tableMap.set(HashBiMap.<TableReference, TableReference>create()); }
@Override public Set<TableReference> getAllTableNames() { //noinspection unused - try-with-resources closes trace try (CloseableTrace trace = startLocalTrace("getAllTableNames()")) { return delegate().getAllTableNames(); } }
Map<TableReference, Double> calculateSweepPriorityScores(Transaction tx, long conservativeSweepTs) { Set<TableReference> allTables = Sets.difference(kvs.getAllTableNames(), AtlasDbConstants.HIDDEN_TABLES); // We read priorities from the past because we should prioritize based on what the sweeper will // actually be able to sweep. We read priorities from the present to make sure we don't repeatedly // sweep the same table while waiting for the past to catch up. List<SweepPriority> oldPriorities = sweepPriorityStore.loadOldPriorities(tx, conservativeSweepTs); List<SweepPriority> newPriorities = sweepPriorityStore.loadNewPriorities(tx); return getSweepScores(tx, allTables, oldPriorities, newPriorities); }
@Test public void getAllTableNames() throws Exception { kvs.getAllTableNames(); checkSpan("atlasdb-kvs.getAllTableNames()"); verify(delegate).getAllTableNames(); verifyNoMoreInteractions(delegate); }
@Test public void getAllTableNamesSlowLogPresentOnInfoLevel() { Appender mockAppender = setLogLevelAndGetAppender(Level.INFO); doAnswer(waitASecondAndAHalf).when(delegate).getAllTableNames(); kvs.getAllTableNames(); verify(mockAppender).doAppend(slowLogMatcher.get()); }
@Test public void getAllTableNamesTraceLogPresentOnTraceLevelEvenIfQueryIsSlow() { Appender mockAppender = setLogLevelAndGetAppender(Level.TRACE); doAnswer(waitASecondAndAHalf).when(delegate).getAllTableNames(); kvs.getAllTableNames(); verify(mockAppender).doAppend(traceLogMatcher.get()); verify(mockAppender).doAppend(slowLogMatcher.get()); }
@Test public void getAllTableNamesNoLoggingHappensIfQueryFastAndInfoLevel() { Appender mockAppender = setLogLevelAndGetAppender(Level.INFO); kvs.getAllTableNames(); verifyNoMoreInteractions(mockAppender); }
@Test public void sweepTableFromStartRowShouldAcceptLowercaseBase16Encodings() { when(kvs.getAllTableNames()).thenReturn(ImmutableSet.of(TABLE_REF)); sweeperService.sweepTableFrom(TABLE_REF.getQualifiedName(), LOWERCASE_BUT_VALID_START_ROW); }
@Test public void sweepTableFromStartRowShouldAcceptMixedCaseBase16Encodings() { when(kvs.getAllTableNames()).thenReturn(ImmutableSet.of(TABLE_REF)); sweeperService.sweepTableFrom(TABLE_REF.getQualifiedName(), MIXED_CASE_START_ROW); }
@Test public void createSyncInitializationTest() { KeyValueService kvs = AsyncInitializeableInMemoryKvs.createAndStartInit(false); assertThat(kvs.isInitialized()).isTrue(); assertThat(kvs.getAllTableNames()).isEmpty(); }
@Test public void asyncInitKvsSynchronous() { KeyValueService kvs = createRawKeyValueService(true); assertThat(kvs.isInitialized()).isTrue(); assertThat(kvs.getAllTableNames()).isEmpty(); }
@Override @Before public void setup() { super.setup(); sweeperService = TestJaxRsClientFactory.createJaxRsClientForTest( SweeperService.class, SweeperServiceImplTest.class, dropwizardClientRule.baseUri().toString()); setupTaskRunner(RESULTS_NO_MORE_TO_SWEEP); when(kvs.getAllTableNames()).thenReturn(ImmutableSet.of(TABLE_REF)); }
@Test public void setupClearsOutExistingTablesExceptAtomic() { toKvs.createTables(TEST_AND_CHECKPOINT_TABLES); fromKvs.dropTables(fromKvs.getAllTableNames()); KeyValueServiceMigrator migrator = KeyValueServiceMigrators.setupMigrator(migratorSpec); migrator.setup(); assertThat(toKvs.getAllTableNames()).containsExactly(TransactionConstants.TRANSACTION_TABLE, AtlasDbConstants.COORDINATION_TABLE); }
@Test public void createAsyncInitializationTest() { KeyValueService kvs = AsyncInitializeableInMemoryKvs.createAndStartInit(true); assertThat(kvs.isInitialized()).isFalse(); assertThatThrownBy(kvs::getAllTableNames) .isInstanceOf(NotInitializedException.class); Awaitility.await().atMost(2, TimeUnit.SECONDS).until(kvs::isInitialized); assertThat(kvs.getAllTableNames()).isEmpty(); } }
@Test public void asyncInitKvsAsynchronous() { KeyValueService kvs = createRawKeyValueService(true); assertThat(kvs.isInitialized()).isFalse(); assertThatThrownBy(kvs::getAllTableNames).isInstanceOf(NotInitializedException.class); Awaitility.await().atMost(2, TimeUnit.SECONDS).until(kvs::isInitialized); assertThat(kvs.getAllTableNames()).isEmpty(); }
@Test public void createTablesWithDifferentCapitalizationCreatesInCassandraAndDoesNotUpdateMetadata() { createTablesIgnoringException(); assertThat(kvs.getAllTableNames()).containsExactlyInAnyOrderElementsOf(TABLES); assertThat(kvs.getMetadataForTables()).isEmpty(); }
@After public void cleanup() { kvs.dropTables(kvs.getAllTableNames()); kvs.truncateTable(AtlasDbConstants.DEFAULT_METADATA_TABLE); }
@Test public void testDeleteTablesForSweepSchema() { Set<TableReference> allTableNames = Sets.newHashSet(); allTableNames.add(TableReference.createFromFullyQualifiedName("sweep.priority")); mockery.checking(new Expectations(){{ oneOf(kvs).getAllTableNames(); will(returnValue(allTableNames)); oneOf(kvs).dropTables(allTableNames); oneOf(kvs).getAllTableNames(); }}); Schemas.deleteTablesAndIndexes(SweepSchema.INSTANCE.getLatestSchema(), kvs); }