private TableReference getTableReferenceUncached(int tableId) { return idToNames.get(tableId) .orElseThrow(() -> new NoSuchElementException("Id " + tableId + " does not exist")); }
@Test public void testWorkflow() { assertThat(idsToNames.getNextId()).isEqualTo(1); assertThat(idsToNames.get(1)).isEmpty(); assertThat(idsToNames.storeNewMapping(tableRef(0), 1)).isTrue(); assertThat(idsToNames.storeNewMapping(tableRef(1), 1)).isFalse(); assertThat(idsToNames.get(1)).contains(tableRef(0)); assertThat(idsToNames.getNextId()).isEqualTo(2); assertThat(idsToNames.storeNewMapping(tableRef(1), 2)).isTrue(); assertThat(idsToNames.getNextId()).isEqualTo(3); }
boolean storeNewMapping(TableReference table, int id) { SweepIdToNameColumn column = SweepIdToNameColumn.of(id); SweepIdToNameColumnValue value = SweepIdToNameColumnValue.of(column, table.getQualifiedName()); Cell cell = Cell.create(rowAsBytes, value.persistColumnName()); CheckAndSetRequest request = CheckAndSetRequest.newCell(ID_TO_NAME, cell, value.persistValue()); try { kvs.checkAndSet(request); return true; } catch (CheckAndSetException e) { return get(id).get().equals(table); } }
private TableReference getTableReferenceUncached(int tableId) { return idToNames.get(tableId) .orElseThrow(() -> new NoSuchElementException("Id " + tableId + " does not exist")); }
boolean storeNewMapping(TableReference table, int id) { SweepIdToNameColumn column = SweepIdToNameColumn.of(id); SweepIdToNameColumnValue value = SweepIdToNameColumnValue.of(column, table.getQualifiedName()); Cell cell = Cell.create(rowAsBytes, value.persistColumnName()); CheckAndSetRequest request = CheckAndSetRequest.newCell(ID_TO_NAME, cell, value.persistValue()); try { kvs.checkAndSet(request); return true; } catch (CheckAndSetException e) { return get(id).get().equals(table); } }