@Override public synchronized void scheduled(ILSMIOOperation operation) throws HyracksDataException { dsInfo.declareActiveIOOperation(); if (operation.getIOOpertionType() == LSMIOOperationType.FLUSH) { pendingFlushes++; FlushOperation flush = (FlushOperation) operation; Map<String, Object> map = operation.getAccessor().getOpContext().getParameters(); Long flushLsn = (Long) map.get(KEY_FLUSH_LOG_LSN); map.put(KEY_FIRST_LSN, firstLsnForCurrentMemoryComponent); map.put(KEY_FLUSHED_COMPONENT_ID, flush.getFlushingComponent().getId()); componentIds.add((ILSMComponentId) map.get(KEY_NEXT_COMPONENT_ID)); firstLsnForCurrentMemoryComponent = flushLsn; // Advance the first lsn for new component } }
@Override public LSMIOOperationStatus call() throws HyracksDataException { accessor.flush(this); return getStatus(); }
callback.beforeOperation(secondFlush); Map<String, Object> firstFlushMap = firstFlush.getAccessor().getOpContext().getParameters(); long firstFlushLogLsn = (Long) firstFlushMap.get(LSMIOOperationCallback.KEY_FLUSH_LOG_LSN); Assert.assertEquals(1, firstFlushLogLsn); final ILSMDiskComponent diskComponent1 = mockDiskComponent(); firstFlush.setNewComponent(diskComponent1); callback.afterOperation(firstFlush); callback.afterFinalize(firstFlush); callback.completed(firstFlush); Map<String, Object> secondFlushMap = secondFlush.getAccessor().getOpContext().getParameters(); long secondFlushLogLsn = (Long) secondFlushMap.get(LSMIOOperationCallback.KEY_FLUSH_LOG_LSN); Assert.assertEquals(2, secondFlushLogLsn); final ILSMDiskComponent diskComponent2 = mockDiskComponent(); secondFlush.setNewComponent(diskComponent2); callback.afterOperation(secondFlush); callback.afterFinalize(secondFlush);
callback.beforeOperation(flush); callback.recycled(mockComponent); flush.setNewComponent(mockDiskComponent()); callback.afterOperation(flush); callback.afterFinalize(flush);
@Override public final ILSMDiskComponent flush(ILSMIOOperation operation) throws HyracksDataException { ILSMIndexAccessor accessor = operation.getAccessor(); ILSMIndexOperationContext opCtx = accessor.getOpContext(); ILSMMemoryComponent memoryComponent = (ILSMMemoryComponent) opCtx.getComponentHolder().get(0); if (memoryComponent != getOldestReadableMemoryComponent()) { throw new IllegalStateException("An attempt to flush a memory component that is not the oldest"); } if (!memoryComponent.isModified() || opCtx.getOperation() == IndexOperation.DELETE_COMPONENTS) { return EmptyComponent.INSTANCE; } if (LOGGER.isInfoEnabled()) { FlushOperation flushOp = (FlushOperation) operation; LOGGER.log(Level.INFO, "Flushing component with id: " + flushOp.getFlushingComponent().getId() + " in the index " + this); } return doFlush(operation); }
@Override public void afterOperation(ILSMIOOperation operation) throws HyracksDataException { if (operation.getStatus() == LSMIOOperationStatus.FAILURE) { return; } if (operation.getIOOpertionType() == LSMIOOperationType.LOAD) { Map<String, Object> map = operation.getParameters(); putComponentIdIntoMetadata(operation.getNewComponent(), (LSMComponentId) map.get(KEY_FLUSHED_COMPONENT_ID)); } else if (operation.getIOOpertionType() == LSMIOOperationType.FLUSH) { Map<String, Object> map = operation.getParameters(); putLSNIntoMetadata(operation.getNewComponent(), (Long) map.get(KEY_FLUSH_LOG_LSN)); putComponentIdIntoMetadata(operation.getNewComponent(), ((FlushOperation) operation).getFlushingComponent().getId()); } else if (operation.getIOOpertionType() == LSMIOOperationType.MERGE) { List<ILSMDiskComponent> mergedComponents = operation.getAccessor().getOpContext().getComponentsToBeMerged(); putLSNIntoMetadata(operation.getNewComponent(), mergedComponents); putComponentIdIntoMetadata(operation.getNewComponent(), mergedComponents); LongPointable markerLsn = LongPointable.FACTORY.createPointable(ComponentUtils.getLong(mergedComponents.get(0).getMetadata(), ComponentUtils.MARKER_LSN_KEY, ComponentUtils.NOT_FOUND, buffer)); operation.getNewComponent().getMetadata().put(ComponentUtils.MARKER_LSN_KEY, markerLsn); } }