All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.hadoop.hbase.tool.WriteSinkCoprocessor Maven / Gradle / Ivy

There is a newer version: 3.0.0-beta-1
Show newest version
/*
 * 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
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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.tool;

import java.io.IOException;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.client.Mutation;
import org.apache.hadoop.hbase.coprocessor.ObserverContext;
import org.apache.hadoop.hbase.coprocessor.RegionCoprocessor;
import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
import org.apache.hadoop.hbase.coprocessor.RegionObserver;
import org.apache.hadoop.hbase.regionserver.MiniBatchOperationInProgress;
import org.apache.hadoop.hbase.regionserver.OperationStatus;
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 

* This coprocessor 'shallows' all the writes. It allows to test a pure write workload, going * through all the communication layers. The reads will work as well, but they as we never write, * they will always always return an empty structure. The WAL is also skipped. Obviously, the region * will never be split automatically. It's up to the user to split and move it. *

*

* For a table created like this: create 'usertable', {NAME => 'f1', VERSIONS => 1} *

*

* You can then add the coprocessor with this command: alter 'usertable', 'coprocessor' => * '|org.apache.hadoop.hbase.tool.WriteSinkCoprocessor|' *

*

* And then put 'usertable', 'f1', 'f1', 'f1' *

*

* scan 'usertable' Will return: 0 row(s) in 0.0050 seconds *

* TODO: It needs tests */ @InterfaceAudience.Private public class WriteSinkCoprocessor implements RegionCoprocessor, RegionObserver { private static final Logger LOG = LoggerFactory.getLogger(WriteSinkCoprocessor.class); private final AtomicLong ops = new AtomicLong(); @Override public Optional getRegionObserver() { return Optional.of(this); } private String regionName; @Override public void preOpen(ObserverContext e) throws IOException { regionName = e.getEnvironment().getRegion().getRegionInfo().getRegionNameAsString(); } @Override public void preBatchMutate(final ObserverContext c, final MiniBatchOperationInProgress miniBatchOp) throws IOException { if (ops.incrementAndGet() % 20000 == 0) { LOG.info("Wrote " + ops.get() + " times in region " + regionName); } for (int i = 0; i < miniBatchOp.size(); i++) { miniBatchOp.setOperationStatus(i, new OperationStatus(HConstants.OperationStatusCode.SUCCESS)); } c.bypass(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy