Search in sources :

Example 61 with Pair

use of com.github.ambry.utils.Pair in project ambry by linkedin.

the class ServerAdminTool method getUserMetadata.

/**
 * Gets user metadata for {@code blobId}.
 * @param dataNodeId the {@link DataNodeId} to contact.
 * @param blobId the {@link BlobId} to operate on.
 * @param getOption the {@link GetOption} to send with the {@link GetRequest}.
 * @param clusterMap the {@link ClusterMap} to use.
 * @return the {@link ServerErrorCode} and user metadata as a {@link ByteBuffer} for {@code blobId}
 * @throws Exception
 */
public Pair<ServerErrorCode, ByteBuffer> getUserMetadata(DataNodeId dataNodeId, BlobId blobId, GetOption getOption, ClusterMap clusterMap) throws Exception {
    Pair<ServerErrorCode, InputStream> response = getGetResponse(dataNodeId, blobId, MessageFormatFlags.BlobUserMetadata, getOption, clusterMap);
    InputStream stream = response.getSecond();
    ByteBuffer userMetadata = stream != null ? MessageFormatRecord.deserializeUserMetadata(stream) : null;
    return new Pair<>(response.getFirst(), userMetadata);
}
Also used : DataInputStream(java.io.DataInputStream) NettyByteBufDataInputStream(com.github.ambry.utils.NettyByteBufDataInputStream) InputStream(java.io.InputStream) ByteBuffer(java.nio.ByteBuffer) ServerErrorCode(com.github.ambry.server.ServerErrorCode) Pair(com.github.ambry.utils.Pair)

Example 62 with Pair

use of com.github.ambry.utils.Pair in project ambry by linkedin.

the class ServerAdminTool method getAll.

/**
 * Gets all data for {@code blobId}.
 * @param dataNodeId the {@link DataNodeId} to contact.
 * @param blobId the {@link BlobId} to operate on.
 * @param getOption the {@link GetOption} to send with the {@link GetRequest}.
 * @param clusterMap the {@link ClusterMap} to use.
 * @param storeKeyFactory the {@link StoreKeyFactory} to use.
 * @return the {@link ServerErrorCode} and {@link BlobAll} for {@code blobId}
 * @throws Exception
 */
public Pair<ServerErrorCode, BlobAll> getAll(DataNodeId dataNodeId, BlobId blobId, GetOption getOption, ClusterMap clusterMap, StoreKeyFactory storeKeyFactory) throws Exception {
    Pair<ServerErrorCode, InputStream> response = getGetResponse(dataNodeId, blobId, MessageFormatFlags.All, getOption, clusterMap);
    InputStream stream = response.getSecond();
    BlobAll blobAll = stream != null ? MessageFormatRecord.deserializeBlobAll(stream, storeKeyFactory) : null;
    return new Pair<>(response.getFirst(), blobAll);
}
Also used : BlobAll(com.github.ambry.messageformat.BlobAll) DataInputStream(java.io.DataInputStream) NettyByteBufDataInputStream(com.github.ambry.utils.NettyByteBufDataInputStream) InputStream(java.io.InputStream) ServerErrorCode(com.github.ambry.server.ServerErrorCode) Pair(com.github.ambry.utils.Pair)

Example 63 with Pair

use of com.github.ambry.utils.Pair in project ambry by linkedin.

the class ServerAdminTool method getBlob.

/**
 * Gets blob data for {@code blobId}.
 * @param dataNodeId the {@link DataNodeId} to contact.
 * @param blobId the {@link BlobId} to operate on.
 * @param getOption the {@link GetOption} to send with the {@link GetRequest}.
 * @param clusterMap the {@link ClusterMap} to use.
 * @return the {@link ServerErrorCode} and {@link BlobData} for {@code blobId}
 * @throws Exception
 */
public Pair<ServerErrorCode, BlobData> getBlob(DataNodeId dataNodeId, BlobId blobId, GetOption getOption, ClusterMap clusterMap) throws Exception {
    Pair<ServerErrorCode, InputStream> response = getGetResponse(dataNodeId, blobId, MessageFormatFlags.Blob, getOption, clusterMap);
    InputStream stream = response.getSecond();
    BlobData blobData = stream != null ? MessageFormatRecord.deserializeBlob(stream) : null;
    return new Pair<>(response.getFirst(), blobData);
}
Also used : DataInputStream(java.io.DataInputStream) NettyByteBufDataInputStream(com.github.ambry.utils.NettyByteBufDataInputStream) InputStream(java.io.InputStream) BlobData(com.github.ambry.messageformat.BlobData) ServerErrorCode(com.github.ambry.server.ServerErrorCode) Pair(com.github.ambry.utils.Pair)

Example 64 with Pair

use of com.github.ambry.utils.Pair in project ambry by linkedin.

the class StoreCopierTest method copyTest.

/**
 * Tests {@link StoreCopier#copy(FindToken)}.
 * @throws Exception
 */
@Test
public void copyTest() throws Exception {
    storeCopier.copy(new StoreFindTokenFactory(STORE_KEY_FACTORY).getNewFindToken());
    storeCopier.close();
    // copy the store descriptor file over
    StoreMetrics storeMetrics = new StoreMetrics(new MetricRegistry());
    Files.copy(new File(srcDir, StoreDescriptor.STORE_DESCRIPTOR_FILENAME).toPath(), new File(tgtDir, StoreDescriptor.STORE_DESCRIPTOR_FILENAME).toPath(), StandardCopyOption.REPLACE_EXISTING);
    BlobStore tgt = new BlobStore(STORE_ID, storeConfig, null, null, DISK_IO_SCHEDULER, StoreTestUtils.DEFAULT_DISK_SPACE_ALLOCATOR, storeMetrics, storeMetrics, tgtDir.getAbsolutePath(), STORE_CAPACITY, STORE_KEY_FACTORY, null, null, time);
    tgt.start();
    try {
        // should not be able to get expired or deleted ids
        StoreKey[] failKeys = { expiredId, deletedId, putTtlUpdatedAndDeletedId };
        for (StoreKey key : failKeys) {
            try {
                tgt.get(Collections.singletonList(key), EnumSet.allOf(StoreGetOptions.class));
                fail("Should have failed to get " + key);
            } catch (StoreException e) {
                assertEquals("Unexpected StoreErrorCode", StoreErrorCodes.ID_Not_Found, e.getErrorCode());
            }
        }
        // should be able to get the non expired, non deleted entries
        Map<StoreKey, Pair<byte[], Long>> successKeys = new HashMap<>();
        successKeys.put(permanentPutId, new Pair<>(permanentPutData, Utils.Infinite_Time));
        successKeys.put(putAndTtlUpdatedId, new Pair<>(putAndTtlUpdatedData, Utils.Infinite_Time));
        successKeys.put(temporaryPutId, new Pair<>(temporaryPutData, temporaryPutExpiryTimeMs));
        for (Map.Entry<StoreKey, Pair<byte[], Long>> entry : successKeys.entrySet()) {
            StoreInfo storeInfo = tgt.get(Collections.singletonList(entry.getKey()), EnumSet.noneOf(StoreGetOptions.class));
            MessageInfo messageInfo = storeInfo.getMessageReadSetInfo().get(0);
            byte[] data = entry.getValue().getFirst();
            assertEquals("Size does not match", data.length, messageInfo.getSize());
            assertEquals("Size does not match", data.length, storeInfo.getMessageReadSet().sizeInBytes(0));
            assertFalse("Should not be deleted or expired", messageInfo.isDeleted() || messageInfo.isExpired());
            assertEquals("Ttl update flag not as expected", putAndTtlUpdatedId.equals(entry.getKey()), messageInfo.isTtlUpdated());
            assertEquals("Expiration time does not match", entry.getValue().getSecond().longValue(), messageInfo.getExpirationTimeInMs());
            ByteBufferChannel channel = new ByteBufferChannel(ByteBuffer.allocate(data.length));
            storeInfo.getMessageReadSet().writeTo(0, channel, 0, data.length);
            assertArrayEquals("Data put does not match data copied", data, channel.getBuffer().array());
        }
    } finally {
        tgt.shutdown();
    }
}
Also used : HashMap(java.util.HashMap) MetricRegistry(com.codahale.metrics.MetricRegistry) ByteBufferChannel(com.github.ambry.utils.ByteBufferChannel) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) ClusterMap(com.github.ambry.clustermap.ClusterMap) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) Pair(com.github.ambry.utils.Pair) Test(org.junit.Test)

Aggregations

Pair (com.github.ambry.utils.Pair)64 ArrayList (java.util.ArrayList)29 HashMap (java.util.HashMap)28 Map (java.util.Map)28 Test (org.junit.Test)20 IOException (java.io.IOException)15 MetricRegistry (com.codahale.metrics.MetricRegistry)14 List (java.util.List)14 ByteBuffer (java.nio.ByteBuffer)13 Collections (java.util.Collections)13 File (java.io.File)12 Assert (org.junit.Assert)12 VerifiableProperties (com.github.ambry.config.VerifiableProperties)11 Utils (com.github.ambry.utils.Utils)10 HashSet (java.util.HashSet)10 Properties (java.util.Properties)10 Container (com.github.ambry.account.Container)9 TestUtils (com.github.ambry.utils.TestUtils)9 Arrays (java.util.Arrays)9 Set (java.util.Set)9