Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 package org.apache.hadoop.hbase.protobuf;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 public class ReplicationProtbufUtil {
A helper to replicate a list of HLog entries using admin protocol.

   public static void replicateWALEntry(final AdminService.BlockingInterface admin,
       final HLog.Entry[] entriesthrows IOException {
     try {
     } catch (ServiceException se) {
       throw ProtobufUtil.getRemoteException(se);

Create a new ReplicateWALEntryRequest from a list of HLog entries

entries the HLog entries to be replicated
a pair of ReplicateWALEntryRequest and a CellScanner over all the WALEdit values found.
       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();
     HBaseProtos.UUID.Builder uuidBuilder = HBaseProtos.UUID.newBuilder();
     for (HLog.Entry entryentries) {
       // TODO: this duplicates a lot in HLogKey#getBuilder
       WALProtos.WALKey.Builder keyBuilder = entryBuilder.getKeyBuilder();
       HLogKey key = entry.getKey();
       if (key.getNonce() != .) {
      if (key.getNonceGroup() != .) {
      for(UUID clusterId : key.getClusterIds()) {
      WALEdit edit = entry.getEdit();
      NavigableMap<byte[], Integerscopes = key.getScopes();
      if (scopes != null && !scopes.isEmpty()) {
        for (Map.Entry<byte[], Integerscopescopes.entrySet()) {
          WALProtos.ScopeType scopeType =
      List<KeyValuekvs = edit.getKeyValues();
      // Add up the size.  It is used later serializing out the kvs.
      for (KeyValue kvkvs) {
        size += kv.getLength();
      // Collect up the kvs
      // Write out how many kvs associated with this entry.
    return new Pair<AdminProtos.ReplicateWALEntryRequestCellScanner>(,


cells packaged as a CellScanner
  static CellScanner getCellScanner(final List<List<? extends Cell>> cellsfinal int size) {
    return new SizedCellScanner() {
      private final Iterator<List<? extends Cell>> entries = cells.iterator();
      private Iterator<? extends CellcurrentIterator = null;
      private Cell currentCell;
      public Cell current() {
        return this.;
      public boolean advance() {
        if (this. == null) {
          if (!this..hasNext()) return false;
          this. =;
        if (this..hasNext()) {
          this. =;
          return true;
        this. = null;
        this. = null;
        return advance();
      public long heapSize() {
        return size;
New to GrepCode? Check out our FAQ X