/** * Returns the URL location of the file on the server where the descriptor is pointing to, * without ip and port information. * <p> * Example locations is: /storageId/descriptorId.itdata * * @param storageData * {@link StorageData} * @param descriptor * {@link StorageDescriptor} * @return URL location without ip and port. */ public String getHttpFileLocation(IStorageData storageData, IStorageDescriptor descriptor) { return this.getHttpFileLocation(storageData, Integer.valueOf(descriptor.getChannelId())); }
Map<Integer, List<IStorageDescriptor>> filesMap = new HashMap<>(); for (IStorageDescriptor storageDescriptor : descriptors) { Integer channelId = Integer.valueOf(storageDescriptor.getChannelId()); List<IStorageDescriptor> oneFileList = filesMap.get(channelId); if (null == oneFileList) {
/** * Returns the {@link Path} of the channel for given {@link StorageData} and * {@link StorageDescriptor}. * * @param storageData * {@link IStorageData} object. * @param descriptor * {@link StorageDescriptor} object. * @return {@link Path} that can be used in IO operations. */ public Path getChannelPath(IStorageData storageData, IStorageDescriptor descriptor) { return getStoragePath(storageData).resolve(descriptor.getChannelId() + StorageFileType.DATA_FILE.getExtension()); }
/** * With minIds we can limit the number of elements returned. * * @throws IndexingException */ @Test public void minIdQuery() throws IndexingException { addElements(arrayBasedStorageLeaf, 100); IndexQuery indexQuery = mock(IndexQuery.class); when(indexQuery.getMinId()).thenReturn(51L); List<IStorageDescriptor> result = arrayBasedStorageLeaf.query(indexQuery); assertThat(result, hasSize(50)); for (IStorageDescriptor descriptor : result) { assertThat(descriptor.getChannelId(), is(LEAF_ID)); } }
@Test public void successfulWrite() throws IndexingException { IStorageDescriptor storageDescriptor = mock(IStorageDescriptor.class); when(storageDescriptor.getChannelId()).thenReturn(1); DefaultData defaultData = mock(DefaultData.class); when(indexingTree.put(defaultData)).thenReturn(storageDescriptor); WriteTask writeTask = mock(WriteTask.class); when(writeTask.getData()).thenReturn(defaultData); int channel = indexingTreeHandler.startWrite(writeTask); assertThat(channel, is(1)); assertThat(indexingTreeHandler.getWriteTaskInProgressCount(), is(1)); long position = 20L; long size = 30L; indexingTreeHandler.writeSuccessful(writeTask, position, size); assertThat(indexingTreeHandler.getWriteTaskInProgressCount(), is(0)); verify(storageDescriptor, times(1)).setPositionAndSize(position, size); }
@Test public void failedWrite() throws IndexingException { IStorageDescriptor storageDescriptor = mock(IStorageDescriptor.class); when(storageDescriptor.getChannelId()).thenReturn(1); DefaultData defaultData = mock(DefaultData.class); when(indexingTree.put(defaultData)).thenReturn(storageDescriptor); WriteTask writeTask = mock(WriteTask.class); when(writeTask.getData()).thenReturn(defaultData); int channel = indexingTreeHandler.startWrite(writeTask); assertThat(channel, is(1)); assertThat(indexingTreeHandler.getWriteTaskInProgressCount(), is(1)); indexingTreeHandler.writeFailed(writeTask); assertThat(indexingTreeHandler.getWriteTaskInProgressCount(), is(0)); verify(storageDescriptor, times(0)).setPositionAndSize(anyLong(), anyLong()); }
/** * Joins the information from the other storage descriptor if possible. This method will return * true if the join was successfully done, and false if no join was done. The join is possible * only if the two descriptors are actually describing the data in the same channel that are * next to each other. There is no difference if the other descriptor is pointing to the data * after or before this descriptor. After successful join the joined data descriptor will be * represented by this descriptor. * * @param other * Descriptor information to join. * @return This method will return true if the join was successfully done, and false if no join * was done. */ public boolean join(IStorageDescriptor other) { if (this.getChannelId() != other.getChannelId()) { return false; } else { return join(other.getPosition(), other.getSize()); } }
/** * {@inheritDoc} */ @Override public int compareTo(IStorageDescriptor other) { if ((this.getChannelId() - other.getChannelId()) != 0) { return this.getChannelId() - other.getChannelId(); } if ((this.getPosition() - other.getPosition()) != 0) { return (int) (this.getPosition() - other.getPosition()); } if ((this.getSize() - other.getSize()) != 0) { return (int) (this.getSize() - other.getSize()); } return 0; }
treeDescriptorPair.setStorageDescriptor(storageDescriptor); return storageDescriptor.getChannelId();
Path absolutePath = storageManager.getChannelPath(storageData, desc.getChannelId()).toAbsolutePath(); allPaths.add(absolutePath);