Search in sources :

Example 1 with ChecksumType

use of com.ms.silverking.cloud.dht.client.ChecksumType in project SilverKing by Morgan-Stanley.

the class SegmentationUtil method getChecksum.

static byte[] getChecksum(ByteBuffer buf) {
    ChecksumType checksumType;
    byte[] checksum;
    checksumType = getChecksumType(buf);
    checksum = new byte[checksumType.length()];
    BufferUtil.get(buf, checksumOffset, checksum, checksumType.length());
    return checksum;
}
Also used : ChecksumType(com.ms.silverking.cloud.dht.client.ChecksumType)

Example 2 with ChecksumType

use of com.ms.silverking.cloud.dht.client.ChecksumType in project SilverKing by Morgan-Stanley.

the class ValueUtil method verifyChecksum.

public static void verifyChecksum(byte[] storedValue, int storedOffset, byte[] value, int valueOffset, int valueLength) throws CorruptValueException {
    byte[] expectedChecksum;
    byte[] actualChecksum;
    ChecksumType checksumType;
    Checksum checksum;
    if (debugChecksum) {
        System.out.println("storedValue: " + StringUtil.byteArrayToHexString(storedValue));
    }
    checksumType = MetaDataUtil.getChecksumType(storedValue, storedOffset);
    if (checksumType != ChecksumType.NONE) {
        actualChecksum = MetaDataUtil.getChecksum(storedValue, storedOffset);
        checksum = ChecksumProvider.getChecksum(checksumType);
        if (!checksum.isEmpty(actualChecksum)) {
            expectedChecksum = checksum.checksum(value, valueOffset, valueLength);
            if (debugChecksum) {
                System.out.println("valueOffset: " + valueOffset);
                System.out.println("valueLength: " + valueLength);
                System.out.println("value: " + StringUtil.byteArrayToHexString(value, valueOffset, valueLength) + "\t" + valueLength);
                System.out.println("value: " + new String(value, valueOffset, valueLength));
                System.out.println("expectedChecksum: " + StringUtil.byteArrayToHexString(expectedChecksum));
                System.out.println("actualChecksum: " + StringUtil.byteArrayToHexString(actualChecksum));
                System.out.flush();
            }
            if (!Arrays.equals(expectedChecksum, actualChecksum)) {
                throw new CorruptValueException(StringUtil.byteArrayToHexString(actualChecksum) + " != " + StringUtil.byteArrayToHexString(expectedChecksum));
            }
        }
    }
}
Also used : Checksum(com.ms.silverking.cloud.dht.client.impl.Checksum) ChecksumType(com.ms.silverking.cloud.dht.client.ChecksumType)

Example 3 with ChecksumType

use of com.ms.silverking.cloud.dht.client.ChecksumType in project SilverKing by Morgan-Stanley.

the class MetaDataUtil method isInvalidated.

public static boolean isInvalidated(byte[] storedValue, int baseOffset) {
    ChecksumType checksumType;
    checksumType = getChecksumType(storedValue, baseOffset);
    if (checksumType == ChecksumType.SYSTEM) {
        byte[] actualChecksum;
        actualChecksum = getChecksum(storedValue, baseOffset);
        return SystemChecksum.isInvalidationChecksum(actualChecksum);
    } else {
        return false;
    }
}
Also used : ChecksumType(com.ms.silverking.cloud.dht.client.ChecksumType)

Example 4 with ChecksumType

use of com.ms.silverking.cloud.dht.client.ChecksumType in project SilverKing by Morgan-Stanley.

the class MetaDataUtil method getChecksumLength.

private static int getChecksumLength(byte[] storedValue, int baseOffset) {
    ChecksumType checksumType;
    checksumType = getChecksumType(storedValue, baseOffset);
    return checksumType.length();
}
Also used : ChecksumType(com.ms.silverking.cloud.dht.client.ChecksumType)

Example 5 with ChecksumType

use of com.ms.silverking.cloud.dht.client.ChecksumType in project SilverKing by Morgan-Stanley.

the class MetaDataUtil method isInvalidated.

public static boolean isInvalidated(ByteBuffer storedValue, int baseOffset) {
    ChecksumType checksumType;
    checksumType = getChecksumType(storedValue, baseOffset);
    if (checksumType == ChecksumType.SYSTEM) {
        byte[] actualChecksum;
        actualChecksum = getChecksum(storedValue, baseOffset);
        return SystemChecksum.isInvalidationChecksum(actualChecksum);
    } else {
        return false;
    }
}
Also used : ChecksumType(com.ms.silverking.cloud.dht.client.ChecksumType)

Aggregations

ChecksumType (com.ms.silverking.cloud.dht.client.ChecksumType)7 Compression (com.ms.silverking.cloud.dht.client.Compression)1 Checksum (com.ms.silverking.cloud.dht.client.impl.Checksum)1 HostAndPort (com.ms.silverking.net.HostAndPort)1