@Override public byte[] uncompress(ByteString data, Enum dictIndex) throws IOException { return WALCellCodec.uncompressByteString(data, compressionContext.getDictionary(dictIndex)); } }
public CompressionContext(Class<? extends Dictionary> dictType, boolean recoveredEdits, boolean hasTagCompression) throws SecurityException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException { Constructor<? extends Dictionary> dictConstructor = dictType.getConstructor(); for (DictionaryIndex dictionaryIndex : DictionaryIndex.values()) { Dictionary newDictionary = dictConstructor.newInstance(); dictionaries.put(dictionaryIndex, newDictionary); } if(recoveredEdits) { getDictionary(DictionaryIndex.REGION).init(1); getDictionary(DictionaryIndex.TABLE).init(1); } else { getDictionary(DictionaryIndex.REGION).init(Short.MAX_VALUE); getDictionary(DictionaryIndex.TABLE).init(Short.MAX_VALUE); } getDictionary(DictionaryIndex.ROW).init(Short.MAX_VALUE); getDictionary(DictionaryIndex.FAMILY).init(Byte.MAX_VALUE); getDictionary(DictionaryIndex.QUALIFIER).init(Byte.MAX_VALUE); if (hasTagCompression) { tagCompressionContext = new TagCompressionContext(dictType, Short.MAX_VALUE); } }
private void writeCompressed(byte[] data, Enum dictIndex) throws IOException { Dictionary dict = compressionContext.getDictionary(dictIndex); assert dict != null; short dictIdx = dict.findEntry(data, 0, data.length); if (dictIdx == Dictionary.NOT_IN_DICTIONARY) { write(Dictionary.NOT_IN_DICTIONARY); StreamUtils.writeRawVInt32(this, data.length); write(data, 0, data.length); } else { StreamUtils.writeShort(this, dictIdx); } } }
@Override public void write(Cell cell) throws IOException { // We first write the KeyValue infrastructure as VInts. StreamUtils.writeRawVInt32(out, KeyValueUtil.keyLength(cell)); StreamUtils.writeRawVInt32(out, cell.getValueLength()); // To support tags int tagsLength = cell.getTagsLength(); StreamUtils.writeRawVInt32(out, tagsLength); PrivateCellUtil.compressRow(out, cell, compression.getDictionary(CompressionContext.DictionaryIndex.ROW)); PrivateCellUtil.compressFamily(out, cell, compression.getDictionary(CompressionContext.DictionaryIndex.FAMILY)); PrivateCellUtil.compressQualifier(out, cell, compression.getDictionary(CompressionContext.DictionaryIndex.QUALIFIER)); // Write timestamp, type and value as uncompressed. StreamUtils.writeLong(out, cell.getTimestamp()); out.write(cell.getTypeByte()); PrivateCellUtil.writeValue(out, cell, cell.getValueLength()); if (tagsLength > 0) { if (compression.tagCompressionContext != null) { // Write tags using Dictionary compression PrivateCellUtil.compressTags(out, cell, compression.tagCompressionContext); } else { // Tag compression is disabled within the WAL compression. Just write the tags bytes as // it is. PrivateCellUtil.writeTags(out, cell, tagsLength); } } } }
compression.getDictionary(CompressionContext.DictionaryIndex.ROW)); checkLength(elemLen, Short.MAX_VALUE); pos = Bytes.putShort(backingArray, pos, (short)elemLen); compression.getDictionary(CompressionContext.DictionaryIndex.FAMILY)); checkLength(elemLen, Byte.MAX_VALUE); pos = Bytes.putByte(backingArray, pos, (byte)elemLen); compression.getDictionary(CompressionContext.DictionaryIndex.QUALIFIER)); pos += elemLen;