throw new IOException("Block InputStream meta file has no FileChannel."); DataChecksum checksum = header.getChecksum(); final int bytesPerChecksum = checksum.getBytesPerChecksum(); final int checksumSize = checksum.getChecksumSize();
try (FileInputStream fis = fileIoProvider.getFileInputStream( this, metaFile)) { dcs = BlockMetadataHeader.readHeader(fis).getChecksum();
DataChecksum dcs = BlockMetadataHeader.readHeader(fis).getChecksum(); int checksumsize = dcs.getChecksumSize(); int bpc = dcs.getBytesPerChecksum();
return 1; DataChecksum checksum = header.getChecksum(); System.out.println("Checksum type: " + checksum.toString()); if (blockFile == null) {
BlockMetadataHeader header = BlockMetadataHeader.readHeader(metaRAF); checksum = header.getChecksum();
/** * Read block metadata header. * * @throws IOException */ void readHeader() throws IOException { //read metadata file header = BlockMetadataHeader.readHeader(checksumIn); checksum = header.getChecksum(); setChecksumSize(checksum.getChecksumSize()); setBytesPerCRC(checksum.getBytesPerChecksum()); long crcPerBlock = checksum.getChecksumSize() <= 0 ? 0 : (metadataIn.getLength() - BlockMetadataHeader.getHeaderSize()) / checksum.getChecksumSize(); setCrcPerBlock(crcPerBlock); setCrcType(checksum.getChecksumType()); }
/** * Convert the replica to a string for debugging purposes. * Note that we can't take the lock here. */ @Override public String toString() { return "ShortCircuitReplica{" + "key=" + key + ", metaHeader.version=" + metaHeader.getVersion() + ", metaHeader.checksum=" + metaHeader.getChecksum() + ", ident=" + "0x" + Integer.toHexString(System.identityHashCode(this)) + ", creationTimeMs=" + creationTimeMs + "}"; } }
/** * Convert the replica to a string for debugging purposes. * Note that we can't take the lock here. */ @Override public String toString() { return new StringBuilder().append("ShortCircuitReplica{"). append("key=").append(key). append(", metaHeader.version=").append(metaHeader.getVersion()). append(", metaHeader.checksum=").append(metaHeader.getChecksum()). append(", ident=").append("0x"). append(Integer.toHexString(System.identityHashCode(this))). append(", creationTimeMs=").append(creationTimeMs). append("}").toString(); } }
/** * Convert the replica to a string for debugging purposes. * Note that we can't take the lock here. */ @Override public String toString() { return new StringBuilder().append("ShortCircuitReplica{"). append("key=").append(key). append(", metaHeader.version=").append(metaHeader.getVersion()). append(", metaHeader.checksum=").append(metaHeader.getChecksum()). append(", ident=").append("0x"). append(Integer.toHexString(System.identityHashCode(this))). append(", creationTimeMs=").append(creationTimeMs). append("}").toString(); } }
/** * This writes all the fields till the beginning of checksum. * @param out DataOutputStream * @throws IOException */ @VisibleForTesting public static void writeHeader(DataOutputStream out, BlockMetadataHeader header) throws IOException { out.writeShort(header.getVersion()); header.getChecksum().writeHeader(out); }
/** * This writes all the fields till the beginning of checksum. * @param out DataOutputStream * @throws IOException */ @VisibleForTesting public static void writeHeader(DataOutputStream out, BlockMetadataHeader header) throws IOException { out.writeShort(header.getVersion()); header.getChecksum().writeHeader(out); }
/** * This writes all the fields till the beginning of checksum. * @param out DataOutputStream * @param header * @return * @throws IOException */ private static void writeHeader(DataOutputStream out, BlockMetadataHeader header) throws IOException { out.writeShort(header.getVersion()); header.getChecksum().writeHeader(out); }
/** * This writes all the fields till the beginning of checksum. * @param out DataOutputStream * @param header * @return * @throws IOException */ private static void writeHeader(DataOutputStream out, BlockMetadataHeader header) throws IOException { out.writeShort(header.getVersion()); header.getChecksum().writeHeader(out); }
/** * This writes all the fields till the beginning of checksum. * @param out DataOutputStream * @throws IOException */ @VisibleForTesting public static void writeHeader(DataOutputStream out, BlockMetadataHeader header) throws IOException { out.writeShort(header.getVersion()); header.getChecksum().writeHeader(out); }
/** * Read the checksum header from the meta input stream. * @return the data checksum obtained from the header. */ public static DataChecksum readDataChecksum(final DataInputStream metaIn, final Object name) throws IOException { // read and handle the common header here. For now just a version final BlockMetadataHeader header = readHeader(metaIn); if (header.getVersion() != VERSION) { LOG.warn("Unexpected meta-file version for " + name + ": version in file is " + header.getVersion() + " but expected version is " + VERSION); } return header.getChecksum(); }
/** * Read the checksum header from the meta input stream. * @return the data checksum obtained from the header. */ public static DataChecksum readDataChecksum(final DataInputStream metaIn, final Object name) throws IOException { // read and handle the common header here. For now just a version final BlockMetadataHeader header = readHeader(metaIn); if (header.getVersion() != VERSION) { LOG.warn("Unexpected meta-file version for " + name + ": version in file is " + header.getVersion() + " but expected version is " + VERSION); } return header.getChecksum(); }
final DataChecksum checksum = header.getChecksum(); final int bytesPerCRC = checksum.getBytesPerChecksum(); final long crcPerBlock = (metadataIn.getLength()
private BlockReaderLocal(Builder builder) { this.replica = builder.replica; this.dataIn = replica.getDataStream().getChannel(); this.dataPos = builder.dataPos; this.checksumIn = replica.getMetaStream().getChannel(); BlockMetadataHeader header = builder.replica.getMetaHeader(); this.checksum = header.getChecksum(); this.verifyChecksum = builder.verifyChecksum && (this.checksum.getChecksumType().id != DataChecksum.CHECKSUM_NULL); this.filename = builder.filename; this.block = builder.block; this.bytesPerChecksum = checksum.getBytesPerChecksum(); this.checksumSize = checksum.getChecksumSize(); this.maxAllocatedChunks = (bytesPerChecksum == 0) ? 0 : ((builder.bufferSize + bytesPerChecksum - 1) / bytesPerChecksum); // Calculate the effective maximum readahead. // We can't do more readahead than there is space in the buffer. int maxReadaheadChunks = (bytesPerChecksum == 0) ? 0 : ((Math.min(builder.bufferSize, builder.maxReadahead) + bytesPerChecksum - 1) / bytesPerChecksum); if (maxReadaheadChunks == 0) { this.zeroReadaheadRequested = true; maxReadaheadChunks = 1; } else { this.zeroReadaheadRequested = false; } this.maxReadaheadLength = maxReadaheadChunks * bytesPerChecksum; this.storageType = builder.storageType; }
/** * Read the checksum header from the meta input stream. * @return the data checksum obtained from the header. */ public static DataChecksum readDataChecksum(final DataInputStream metaIn, final Object name) throws IOException { // read and handle the common header here. For now just a version final BlockMetadataHeader header = readHeader(metaIn); if (header.getVersion() != VERSION) { LOG.warn("Unexpected meta-file version for " + name + ": version in file is " + header.getVersion() + " but expected version is " + VERSION); } return header.getChecksum(); }
private BlockReaderLocal(Builder builder) { this.replica = builder.replica; this.dataIn = replica.getDataStream().getChannel(); this.dataPos = builder.dataPos; this.checksumIn = replica.getMetaStream().getChannel(); BlockMetadataHeader header = builder.replica.getMetaHeader(); this.checksum = header.getChecksum(); this.verifyChecksum = builder.verifyChecksum && (this.checksum.getChecksumType().id != DataChecksum.CHECKSUM_NULL); this.filename = builder.filename; this.block = builder.block; this.bytesPerChecksum = checksum.getBytesPerChecksum(); this.checksumSize = checksum.getChecksumSize(); this.maxAllocatedChunks = (bytesPerChecksum == 0) ? 0 : ((builder.bufferSize + bytesPerChecksum - 1) / bytesPerChecksum); // Calculate the effective maximum readahead. // We can't do more readahead than there is space in the buffer. int maxReadaheadChunks = (bytesPerChecksum == 0) ? 0 : ((Math.min(builder.bufferSize, builder.maxReadahead) + bytesPerChecksum - 1) / bytesPerChecksum); if (maxReadaheadChunks == 0) { this.zeroReadaheadRequested = true; maxReadaheadChunks = 1; } else { this.zeroReadaheadRequested = false; } this.maxReadaheadLength = maxReadaheadChunks * bytesPerChecksum; this.storageType = builder.storageType; }