public static FlushDescriptor toFlushDescriptor(FlushAction action, HRegionInfo hri, long flushSeqId, Map<byte[], List<Path>> committedFiles) { FlushDescriptor.Builder desc = FlushDescriptor.newBuilder() .setAction(action) .setEncodedRegionName(ByteStringer.wrap(hri.getEncodedNameAsBytes())) .setRegionName(ByteStringer.wrap(hri.getRegionName())) .setFlushSequenceNumber(flushSeqId) .setTableName(ByteStringer.wrap(hri.getTable().getName())); for (Map.Entry<byte[], List<Path>> entry : committedFiles.entrySet()) { WALProtos.FlushDescriptor.StoreFlushDescriptor.Builder builder = WALProtos.FlushDescriptor.StoreFlushDescriptor.newBuilder() .setFamilyName(ByteStringer.wrap(entry.getKey())) .setStoreHomeDir(Bytes.toString(entry.getKey())); //relative to region if (entry.getValue() != null) { for (Path path : entry.getValue()) { builder.addFlushOutput(path.getName()); } } desc.addStoreFlushes(builder); } return desc.build(); }
/** * Generates a marker for the WAL so that we propagate the notion of a bulk region load * throughout the WAL. * * @param tableName The tableName into which the bulk load is being imported into. * @param encodedRegionName Encoded region name of the region which is being bulk loaded. * @param storeFiles A set of store files of a column family are bulk loaded. * @param bulkloadSeqId sequence ID (by a force flush) used to create bulk load hfile * name * @return The WAL log marker for bulk loads. */ public static WALProtos.BulkLoadDescriptor toBulkLoadDescriptor(TableName tableName, ByteString encodedRegionName, Map<byte[], List<Path>> storeFiles, long bulkloadSeqId) { BulkLoadDescriptor.Builder desc = BulkLoadDescriptor.newBuilder() .setTableName(ProtobufUtil.toProtoTableName(tableName)) .setEncodedRegionName(encodedRegionName).setBulkloadSeqNum(bulkloadSeqId); for (Map.Entry<byte[], List<Path>> entry : storeFiles.entrySet()) { WALProtos.StoreDescriptor.Builder builder = StoreDescriptor.newBuilder() .setFamilyName(ByteStringer.wrap(entry.getKey())) .setStoreHomeDir(Bytes.toString(entry.getKey())); // relative to region for (Path path : entry.getValue()) { builder.addStoreFile(path.getName()); } desc.addStores(builder); } return desc.build(); }
public static FlushDescriptor toFlushDescriptor(FlushAction action, HRegionInfo hri, long flushSeqId, Map<byte[], List<Path>> committedFiles) { FlushDescriptor.Builder desc = FlushDescriptor.newBuilder() .setAction(action) .setEncodedRegionName(ByteStringer.wrap(hri.getEncodedNameAsBytes())) .setFlushSequenceNumber(flushSeqId) .setTableName(ByteStringer.wrap(hri.getTable().getName())); for (Map.Entry<byte[], List<Path>> entry : committedFiles.entrySet()) { WALProtos.FlushDescriptor.StoreFlushDescriptor.Builder builder = WALProtos.FlushDescriptor.StoreFlushDescriptor.newBuilder() .setFamilyName(ByteStringer.wrap(entry.getKey())) .setStoreHomeDir(Bytes.toString(entry.getKey())); //relative to region if (entry.getValue() != null) { for (Path path : entry.getValue()) { builder.addFlushOutput(path.getName()); } } desc.addStoreFlushes(builder); } return desc.build(); }
private String initInternal(FSDataInputStream stream, boolean isFirst) throws IOException { close(); long expectedPos = PB_WAL_MAGIC.length; if (stream == null) { stream = fs.open(path); stream.seek(expectedPos); } if (stream.getPos() != expectedPos) { throw new IOException("The stream is at invalid position: " + stream.getPos()); } // Initialize metadata or, when we reset, just skip the header. WALProtos.WALHeader.Builder builder = WALProtos.WALHeader.newBuilder(); WALHdrContext hdrCtxt = readHeader(builder, stream); WALHdrResult walHdrRes = hdrCtxt.getResult(); if (walHdrRes == WALHdrResult.EOF) { throw new EOFException("Couldn't read WAL PB header"); } if (walHdrRes == WALHdrResult.UNKNOWN_WRITER_CLS) { throw new IOException("Got unknown writer class: " + builder.getWriterClsName()); } if (isFirst) { WALProtos.WALHeader header = builder.build(); this.hasCompression = header.hasHasCompression() && header.getHasCompression(); this.hasTagCompression = header.hasHasTagCompression() && header.getHasTagCompression(); } this.inputStream = stream; this.walEditsStopOffset = this.fileLength; long currentPosition = stream.getPos(); trailerPresent = setTrailerIfPresent(); this.seekOnFs(currentPosition); if (LOG.isTraceEnabled()) { LOG.trace("After reading the trailer: walEditsStopOffset: " + this.walEditsStopOffset + ", fileLength: " + this.fileLength + ", " + "trailerPresent: " + trailerPresent); } codecClsName = hdrCtxt.getCellCodecClsName(); return hdrCtxt.getCellCodecClsName(); }
/** * Create a bulk loader WALEdit * * @param hri The HRegionInfo for the region in which we are bulk loading * @param bulkLoadDescriptor The descriptor for the Bulk Loader * @return The WALEdit for the BulkLoad */ public static WALEdit createBulkLoadEvent(HRegionInfo hri, WALProtos.BulkLoadDescriptor bulkLoadDescriptor) { KeyValue kv = new KeyValue(getRowForRegion(hri), METAFAMILY, BULK_LOAD, EnvironmentEdgeManager.currentTime(), bulkLoadDescriptor.toByteArray()); return new WALEdit().add(kv); }
/** * Deserialized and returns a BulkLoadDescriptor from the passed in Cell * @param cell the key value * @return deserialized BulkLoadDescriptor or null. */ public static WALProtos.BulkLoadDescriptor getBulkLoadDescriptor(Cell cell) throws IOException { if (CellUtil.matchingColumn(cell, METAFAMILY, BULK_LOAD)) { return WALProtos.BulkLoadDescriptor.parseFrom(cell.getValue()); } return null; }
/** * Write a log marker that a bulk load has succeeded and is about to be committed. * * @param wal The log to write into. * @param htd A description of the table that we are bulk loading into. * @param hri A description of the region in the table that we are bulk loading into. * @param desc A protocol buffers based description of the client's bulk loading request * @return txid of this transaction or if nothing to do, the last txid * @throws IOException We will throw an IOException if we can not append to the HLog. */ public static long writeBulkLoadMarkerAndSync(final WAL wal, final HTableDescriptor htd, final HRegionInfo hri, final WALProtos.BulkLoadDescriptor desc, final MultiVersionConcurrencyControl mvcc) throws IOException { long trx = writeMarker(wal, htd, hri, WALEdit.createBulkLoadEvent(hri, desc), mvcc, true); if (LOG.isTraceEnabled()) { LOG.trace("Appended Bulk Load marker " + TextFormat.shortDebugString(desc)); } return trx; }
/** * Test for HBASE-9038, Replication.scopeWALEdits would NPE if it wasn't filtering out * the compaction WALEdit * @throws Exception */ @Test(timeout=300000) public void testCompactionWALEdits() throws Exception { WALProtos.CompactionDescriptor compactionDescriptor = WALProtos.CompactionDescriptor.getDefaultInstance(); HRegionInfo hri = new HRegionInfo(htable1.getName(), HConstants.EMPTY_START_ROW, HConstants.EMPTY_END_ROW); WALEdit edit = WALEdit.createCompaction(hri, compactionDescriptor); Replication.scopeWALEdits(htable1.getTableDescriptor(), new WALKey(), edit); }
private String initInternal(FSDataInputStream stream, boolean isFirst) throws IOException { close(); long expectedPos = PB_WAL_MAGIC.length; if (stream == null) { stream = fs.open(path); stream.seek(expectedPos); } if (stream.getPos() != expectedPos) { throw new IOException("The stream is at invalid position: " + stream.getPos()); } // Initialize metadata or, when we reset, just skip the header. WALProtos.WALHeader.Builder builder = WALProtos.WALHeader.newBuilder(); WALHdrContext hdrCtxt = readHeader(builder, stream); WALHdrResult walHdrRes = hdrCtxt.getResult(); if (walHdrRes == WALHdrResult.EOF) { throw new EOFException("Couldn't read WAL PB header"); } if (walHdrRes == WALHdrResult.UNKNOWN_WRITER_CLS) { throw new IOException("Got unknown writer class: " + builder.getWriterClsName()); } if (isFirst) { WALProtos.WALHeader header = builder.build(); this.hasCompression = header.hasHasCompression() && header.getHasCompression(); this.hasTagCompression = header.hasHasTagCompression() && header.getHasTagCompression(); } this.inputStream = stream; this.walEditsStopOffset = this.fileLength; long currentPosition = stream.getPos(); trailerPresent = setTrailerIfPresent(); this.seekOnFs(currentPosition); if (LOG.isTraceEnabled()) { LOG.trace("After reading the trailer: walEditsStopOffset: " + this.walEditsStopOffset + ", fileLength: " + this.fileLength + ", " + "trailerPresent: " + trailerPresent); } return hdrCtxt.getCellCodecClsName(); }
private void initInternal(FSDataInputStream stream, boolean isFirst) throws IOException { close(); long expectedPos = PB_WAL_MAGIC.length; if (stream == null) { stream = fs.open(path); stream.seek(expectedPos); } if (stream.getPos() != expectedPos) { throw new IOException("The stream is at invalid position: " + stream.getPos()); } // Initialize metadata or, when we reset, just skip the header. WALProtos.WALHeader.Builder builder = WALProtos.WALHeader.newBuilder(); boolean hasHeader = readHeader(builder, stream); if (!hasHeader) { throw new EOFException("Couldn't read WAL PB header"); } if (isFirst) { WALProtos.WALHeader header = builder.build(); this.hasCompression = header.hasHasCompression() && header.getHasCompression(); this.hasTagCompression = header.hasHasTagCompression() && header.getHasTagCompression(); } this.inputStream = stream; this.walEditsStopOffset = this.fileLength; long currentPosition = stream.getPos(); trailerPresent = setTrailerIfPresent(); this.seekOnFs(currentPosition); if (LOG.isTraceEnabled()) { LOG.trace("After reading the trailer: walEditsStopOffset: " + this.walEditsStopOffset + ", fileLength: " + this.fileLength + ", " + "trailerPresent: " + trailerPresent); } }
/** * Test for HBASE-9038, Replication.scopeWALEdits would NPE if it wasn't filtering out * the compaction WALEdit * @throws Exception */ @Test(timeout=300000) public void testCompactionWALEdits() throws Exception { WALProtos.CompactionDescriptor compactionDescriptor = WALProtos.CompactionDescriptor.getDefaultInstance(); WALEdit edit = WALEdit.createCompaction(compactionDescriptor); Replication.scopeWALEdits(htable1.getTableDescriptor(), new HLogKey(), edit); }
private void initInternal(FSDataInputStream stream, boolean isFirst) throws IOException { close(); long expectedPos = PB_WAL_MAGIC.length; if (stream == null) { stream = fs.open(path); stream.seek(expectedPos); } if (stream.getPos() != expectedPos) { throw new IOException("The stream is at invalid position: " + stream.getPos()); } // Initialize metadata or, when we reset, just skip the header. WALProtos.WALHeader.Builder builder = WALProtos.WALHeader.newBuilder(); boolean hasHeader = builder.mergeDelimitedFrom(stream); if (!hasHeader) { throw new EOFException("Couldn't read WAL PB header"); } if (isFirst) { WALProtos.WALHeader header = builder.build(); this.hasCompression = header.hasHasCompression() && header.getHasCompression(); } this.inputStream = stream; this.walEditsStopOffset = this.fileLength; long currentPosition = stream.getPos(); trailerPresent = setTrailerIfPresent(); this.seekOnFs(currentPosition); if (LOG.isTraceEnabled()) { LOG.trace("After reading the trailer: walEditsStopOffset: " + this.walEditsStopOffset + ", fileLength: " + this.fileLength + ", " + "trailerPresent: " + trailerPresent); } }
/** * Create a new ReplicateWALEntryRequest from a list of HLog entries * * @param entries the HLog entries to be replicated * @param encodedRegionName alternative region name to use if not null * @return a pair of ReplicateWALEntryRequest and a CellScanner over all the WALEdit values * found. */ public static Pair<AdminProtos.ReplicateWALEntryRequest, CellScanner> buildReplicateWALEntryRequest(final Entry[] entries, byte[] encodedRegionName) { // Accumulate all the KVs seen in here. List<List<? extends Cell>> allCells = new ArrayList<List<? extends Cell>>(entries.length); int size = 0; WALProtos.FamilyScope.Builder scopeBuilder = WALProtos.FamilyScope.newBuilder(); AdminProtos.WALEntry.Builder entryBuilder = AdminProtos.WALEntry.newBuilder(); AdminProtos.ReplicateWALEntryRequest.Builder builder = AdminProtos.ReplicateWALEntryRequest.newBuilder(); HBaseProtos.UUID.Builder uuidBuilder = HBaseProtos.UUID.newBuilder(); for (Entry entry: entries) { entryBuilder.clear(); // TODO: this duplicates a lot in WALKey#getBuilder WALProtos.WALKey.Builder keyBuilder = entryBuilder.getKeyBuilder(); WALKey key = entry.getKey(); keyBuilder.setEncodedRegionName( ByteStringer.wrap(encodedRegionName == null ? key.getEncodedRegionName() : encodedRegionName)); keyBuilder.setTableName(ByteStringer.wrap(key.getTablename().getName())); keyBuilder.setLogSequenceNumber(key.getLogSeqNum()); keyBuilder.setWriteTime(key.getWriteTime()); if (key.getNonce() != HConstants.NO_NONCE) { keyBuilder.setNonce(key.getNonce()); } if (key.getNonceGroup() != HConstants.NO_NONCE) { keyBuilder.setNonceGroup(key.getNonceGroup()); } for(UUID clusterId : key.getClusterIds()) { uuidBuilder.setLeastSigBits(clusterId.getLeastSignificantBits()); uuidBuilder.setMostSigBits(clusterId.getMostSignificantBits()); keyBuilder.addClusterIds(uuidBuilder.build()); } if(key.getOrigLogSeqNum() > 0) { keyBuilder.setOrigSequenceNumber(key.getOrigLogSeqNum()); } WALEdit edit = entry.getEdit(); NavigableMap<byte[], Integer> scopes = key.getScopes(); if (scopes != null && !scopes.isEmpty()) { for (Map.Entry<byte[], Integer> scope: scopes.entrySet()) { scopeBuilder.setFamily(ByteStringer.wrap(scope.getKey())); WALProtos.ScopeType scopeType = WALProtos.ScopeType.valueOf(scope.getValue().intValue()); scopeBuilder.setScopeType(scopeType); keyBuilder.addScopes(scopeBuilder.build()); } } List<Cell> cells = edit.getCells(); // Add up the size. It is used later serializing out the cells. for (Cell cell: cells) { size += CellUtil.estimatedSerializedSizeOf(cell); } // Collect up the cells allCells.add(cells); // Write out how many cells associated with this entry. entryBuilder.setAssociatedCellCount(cells.size()); builder.addEntry(entryBuilder.build()); } return new Pair<AdminProtos.ReplicateWALEntryRequest, CellScanner>(builder.build(), getCellScanner(allCells, size)); }
/** * Create a new ReplicateWALEntryRequest from a list of WAL entries * * @param entries the WAL entries to be replicated * @return a pair of ReplicateWALEntryRequest and a CellScanner over all the WALEdit values * found. */ public static Pair<AdminProtos.ReplicateWALEntryRequest, CellScanner> buildReplicateWALEntryRequest(final Entry[] entries) { // Accumulate all the Cells seen in here. List<List<? extends Cell>> allCells = new ArrayList<List<? extends Cell>>(entries.length); int size = 0; WALProtos.FamilyScope.Builder scopeBuilder = WALProtos.FamilyScope.newBuilder(); AdminProtos.WALEntry.Builder entryBuilder = AdminProtos.WALEntry.newBuilder(); AdminProtos.ReplicateWALEntryRequest.Builder builder = AdminProtos.ReplicateWALEntryRequest.newBuilder(); HBaseProtos.UUID.Builder uuidBuilder = HBaseProtos.UUID.newBuilder(); for (Entry entry: entries) { entryBuilder.clear(); // TODO: this duplicates a lot in WALKey#getBuilder WALProtos.WALKey.Builder keyBuilder = entryBuilder.getKeyBuilder(); WALKey key = entry.getKey(); keyBuilder.setEncodedRegionName( ByteStringer.wrap(key.getEncodedRegionName())); keyBuilder.setTableName(ByteStringer.wrap(key.getTablename().getName())); keyBuilder.setLogSequenceNumber(key.getLogSeqNum()); keyBuilder.setWriteTime(key.getWriteTime()); if (key.getNonce() != HConstants.NO_NONCE) { keyBuilder.setNonce(key.getNonce()); } if (key.getNonceGroup() != HConstants.NO_NONCE) { keyBuilder.setNonceGroup(key.getNonceGroup()); } for(UUID clusterId : key.getClusterIds()) { uuidBuilder.setLeastSigBits(clusterId.getLeastSignificantBits()); uuidBuilder.setMostSigBits(clusterId.getMostSignificantBits()); keyBuilder.addClusterIds(uuidBuilder.build()); } if(key.getOrigLogSeqNum() > 0) { keyBuilder.setOrigSequenceNumber(key.getOrigLogSeqNum()); } WALEdit edit = entry.getEdit(); NavigableMap<byte[], Integer> scopes = key.getScopes(); if (scopes != null && !scopes.isEmpty()) { for (Map.Entry<byte[], Integer> scope: scopes.entrySet()) { scopeBuilder.setFamily(ByteStringer.wrap(scope.getKey())); WALProtos.ScopeType scopeType = WALProtos.ScopeType.valueOf(scope.getValue().intValue()); scopeBuilder.setScopeType(scopeType); keyBuilder.addScopes(scopeBuilder.build()); } } List<Cell> cells = edit.getCells(); // Add up the size. It is used later serializing out the cells. for (Cell cell: cells) { size += CellUtil.estimatedSerializedSizeOf(cell); } // Collect up the cells allCells.add(cells); // Write out how many cells associated with this entry. entryBuilder.setAssociatedCellCount(cells.size()); builder.addEntry(entryBuilder.build()); } return new Pair<AdminProtos.ReplicateWALEntryRequest, CellScanner>(builder.build(), getCellScanner(allCells, size)); }
/** * Create a new ReplicateWALEntryRequest from a list of HLog entries * * @param entries the HLog entries to be replicated * @return a pair of ReplicateWALEntryRequest and a CellScanner over all the WALEdit values * found. */ public static Pair<AdminProtos.ReplicateWALEntryRequest, CellScanner> buildReplicateWALEntryRequest(final HLog.Entry[] entries) { // Accumulate all the KVs seen in here. List<List<? extends Cell>> allkvs = new ArrayList<List<? extends Cell>>(entries.length); int size = 0; WALProtos.FamilyScope.Builder scopeBuilder = WALProtos.FamilyScope.newBuilder(); AdminProtos.WALEntry.Builder entryBuilder = AdminProtos.WALEntry.newBuilder(); AdminProtos.ReplicateWALEntryRequest.Builder builder = AdminProtos.ReplicateWALEntryRequest.newBuilder(); HBaseProtos.UUID.Builder uuidBuilder = HBaseProtos.UUID.newBuilder(); for (HLog.Entry entry: entries) { entryBuilder.clear(); // TODO: this duplicates a lot in HLogKey#getBuilder WALProtos.WALKey.Builder keyBuilder = entryBuilder.getKeyBuilder(); HLogKey key = entry.getKey(); keyBuilder.setEncodedRegionName( HBaseZeroCopyByteString.wrap(key.getEncodedRegionName())); keyBuilder.setTableName(HBaseZeroCopyByteString.wrap(key.getTablename().getName())); keyBuilder.setLogSequenceNumber(key.getLogSeqNum()); keyBuilder.setWriteTime(key.getWriteTime()); if (key.getNonce() != HConstants.NO_NONCE) { keyBuilder.setNonce(key.getNonce()); } if (key.getNonceGroup() != HConstants.NO_NONCE) { keyBuilder.setNonceGroup(key.getNonceGroup()); } for(UUID clusterId : key.getClusterIds()) { uuidBuilder.setLeastSigBits(clusterId.getLeastSignificantBits()); uuidBuilder.setMostSigBits(clusterId.getMostSignificantBits()); keyBuilder.addClusterIds(uuidBuilder.build()); } WALEdit edit = entry.getEdit(); NavigableMap<byte[], Integer> scopes = key.getScopes(); if (scopes != null && !scopes.isEmpty()) { for (Map.Entry<byte[], Integer> scope: scopes.entrySet()) { scopeBuilder.setFamily(HBaseZeroCopyByteString.wrap(scope.getKey())); WALProtos.ScopeType scopeType = WALProtos.ScopeType.valueOf(scope.getValue().intValue()); scopeBuilder.setScopeType(scopeType); keyBuilder.addScopes(scopeBuilder.build()); } } List<KeyValue> kvs = edit.getKeyValues(); // Add up the size. It is used later serializing out the kvs. for (KeyValue kv: kvs) { size += kv.getLength(); } // Collect up the kvs allkvs.add(kvs); // Write out how many kvs associated with this entry. entryBuilder.setAssociatedCellCount(kvs.size()); builder.addEntry(entryBuilder.build()); } return new Pair<AdminProtos.ReplicateWALEntryRequest, CellScanner>(builder.build(), getCellScanner(allkvs, size)); }
/** * Create a new ReplicateWALEntryRequest from a list of HLog entries * * @param entries the HLog entries to be replicated * @return a pair of ReplicateWALEntryRequest and a CellScanner over all the WALEdit values * found. */ public static Pair<AdminProtos.ReplicateWALEntryRequest, CellScanner> buildReplicateWALEntryRequest(final HLog.Entry[] entries) { // Accumulate all the KVs seen in here. List<List<? extends Cell>> allkvs = new ArrayList<List<? extends Cell>>(entries.length); int size = 0; WALProtos.FamilyScope.Builder scopeBuilder = WALProtos.FamilyScope.newBuilder(); AdminProtos.WALEntry.Builder entryBuilder = AdminProtos.WALEntry.newBuilder(); AdminProtos.ReplicateWALEntryRequest.Builder builder = AdminProtos.ReplicateWALEntryRequest.newBuilder(); HBaseProtos.UUID.Builder uuidBuilder = HBaseProtos.UUID.newBuilder(); for (HLog.Entry entry: entries) { entryBuilder.clear(); WALProtos.WALKey.Builder keyBuilder = entryBuilder.getKeyBuilder(); HLogKey key = entry.getKey(); keyBuilder.setEncodedRegionName( ZeroCopyLiteralByteString.wrap(key.getEncodedRegionName())); keyBuilder.setTableName(ZeroCopyLiteralByteString.wrap(key.getTablename().getName())); keyBuilder.setLogSequenceNumber(key.getLogSeqNum()); keyBuilder.setWriteTime(key.getWriteTime()); for(UUID clusterId : key.getClusterIds()) { uuidBuilder.setLeastSigBits(clusterId.getLeastSignificantBits()); uuidBuilder.setMostSigBits(clusterId.getMostSignificantBits()); keyBuilder.addClusterIds(uuidBuilder.build()); } WALEdit edit = entry.getEdit(); NavigableMap<byte[], Integer> scopes = key.getScopes(); if (scopes != null && !scopes.isEmpty()) { for (Map.Entry<byte[], Integer> scope: scopes.entrySet()) { scopeBuilder.setFamily(ZeroCopyLiteralByteString.wrap(scope.getKey())); WALProtos.ScopeType scopeType = WALProtos.ScopeType.valueOf(scope.getValue().intValue()); scopeBuilder.setScopeType(scopeType); keyBuilder.addScopes(scopeBuilder.build()); } } List<KeyValue> kvs = edit.getKeyValues(); // Add up the size. It is used later serializing out the kvs. for (KeyValue kv: kvs) { size += kv.getLength(); } // Collect up the kvs allkvs.add(kvs); // Write out how many kvs associated with this entry. entryBuilder.setAssociatedCellCount(kvs.size()); builder.addEntry(entryBuilder.build()); } return new Pair<AdminProtos.ReplicateWALEntryRequest, CellScanner>(builder.build(), getCellScanner(allkvs, size)); }