/** * Write trailer data as protobuf. * NOTE: we run a translation on the comparator name and will serialize the old hbase-1.x where * it makes sense. See {@link #getHBase1CompatibleName(String)}. */ void serializeAsPB(DataOutputStream output) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); // We need this extra copy unfortunately to determine the final size of the // delimited output, see use of baos.size() below. toProtobuf().writeDelimitedTo(baos); baos.writeTo(output); // Pad to make up the difference between variable PB encoding length and the // length when encoded as writable under earlier V2 formats. Failure to pad // properly or if the PB encoding is too big would mean the trailer wont be read // in properly by HFile. int padding = getTrailerSize() - NOT_PB_SIZE - baos.size(); if (padding < 0) { throw new IOException("Pbuf encoding size exceeded fixed trailer size limit"); } for (int i = 0; i < padding; i++) { output.write(0); } }
@Test public void testComparatorIsHBase1Compatible() { FixedFileTrailer t = new FixedFileTrailer(version, HFileReaderImpl.PBUF_TRAILER_MINOR_VERSION); t.setComparatorClass(CellComparatorImpl.COMPARATOR.getClass()); assertEquals(CellComparatorImpl.COMPARATOR.getClass().getName(), t.getComparatorClassName()); HFileProtos.FileTrailerProto pb = t.toProtobuf(); assertEquals(KeyValue.COMPARATOR.getClass().getName(), pb.getComparatorClassName()); t.setComparatorClass(CellComparatorImpl.MetaCellComparator.META_COMPARATOR.getClass()); pb = t.toProtobuf(); assertEquals(KeyValue.META_COMPARATOR.getClass().getName(), pb.getComparatorClassName()); }
@Test public void testComparatorIsHBase1Compatible() { FixedFileTrailer t = new FixedFileTrailer(version, HFileReaderImpl.PBUF_TRAILER_MINOR_VERSION); t.setComparatorClass(CellComparatorImpl.COMPARATOR.getClass()); assertEquals(CellComparatorImpl.COMPARATOR.getClass().getName(), t.getComparatorClassName()); HFileProtos.FileTrailerProto pb = t.toProtobuf(); assertEquals(KeyValue.COMPARATOR.getClass().getName(), pb.getComparatorClassName()); t.setComparatorClass(CellComparatorImpl.MetaCellComparator.META_COMPARATOR.getClass()); pb = t.toProtobuf(); assertEquals(KeyValue.META_COMPARATOR.getClass().getName(), pb.getComparatorClassName()); }