public LSMComponentIdGenerator(int numComponents, long lastUsedId) { this.numComponents = numComponents; this.lastUsedId = lastUsedId; refresh(); currentComponentIndex = 0; }
Mockito.when(mockIndex.getCurrentMemoryComponent()).thenReturn(Mockito.mock(AbstractLSMMemoryComponent.class)); DatasetInfo dsInfo = new DatasetInfo(101, null); LSMComponentIdGenerator idGenerator = new LSMComponentIdGenerator(numMemoryComponents, MIN_VALID_COMPONENT_ID); LSMIOOperationCallback callback = new LSMIOOperationCallback(dsInfo, mockIndex, idGenerator.getId(), mockIndexCheckpointManagerProvider()); idGenerator.refresh(); long flushLsn = 1L; ILSMComponentId nextComponentId = idGenerator.getId(); Map<String, Object> flushMap = new HashMap<>(); flushMap.put(LSMIOOperationCallback.KEY_FLUSH_LOG_LSN, flushLsn); idGenerator.refresh(); flushLsn = 2L; nextComponentId = idGenerator.getId(); flushMap = new HashMap<>(); flushMap.put(LSMIOOperationCallback.KEY_FLUSH_LOG_LSN, flushLsn);
private void populateOpTrackerAndIdGenerator(DatasetResource dataset, int partition, String path) { final long lastValidId = getDatasetLastValidComponentId(path); ILSMComponentIdGenerator idGenerator = new LSMComponentIdGenerator(storageProperties.getMemoryComponentsNum(), lastValidId); PrimaryIndexOperationTracker opTracker = new PrimaryIndexOperationTracker(dataset.getDatasetID(), partition, logManager, dataset.getDatasetInfo(), idGenerator); dataset.setPrimaryIndexOperationTracker(partition, opTracker); dataset.setIdGenerator(partition, idGenerator); }
@Test public void testAllocateComponentId() throws HyracksDataException { int numMemoryComponents = 2; DatasetInfo dsInfo = new DatasetInfo(101, null); ILSMComponentIdGenerator idGenerator = new LSMComponentIdGenerator(numMemoryComponents, MIN_VALID_COMPONENT_ID); ILSMIndex mockIndex = Mockito.mock(ILSMIndex.class); Mockito.when(mockIndex.getNumberOfAllMemoryComponents()).thenReturn(numMemoryComponents); ILSMMemoryComponent mockComponent = Mockito.mock(AbstractLSMMemoryComponent.class); Mockito.when(mockIndex.getCurrentMemoryComponent()).thenReturn(mockComponent); LSMIOOperationCallback callback = new LSMIOOperationCallback(dsInfo, mockIndex, idGenerator.getId(), mockIndexCheckpointManagerProvider()); ILSMComponentId initialId = idGenerator.getId(); // simulate a partition is flushed before allocated idGenerator.refresh(); long flushLsn = 1L; ILSMComponentId nextComponentId = idGenerator.getId(); callback.allocated(mockComponent); callback.recycled(mockComponent); checkMemoryComponent(initialId, mockComponent); }
int numMemoryComponents = 2; DatasetInfo dsInfo = new DatasetInfo(101, null); ILSMComponentIdGenerator idGenerator = new LSMComponentIdGenerator(numMemoryComponents, MIN_VALID_COMPONENT_ID); ILSMIndex mockIndex = Mockito.mock(ILSMIndex.class); Mockito.when(mockIndex.getNumberOfAllMemoryComponents()).thenReturn(numMemoryComponents);