@Override public Object invoke(Object instance, final Method method, final Object[] args) throws Throwable { if (LOG.isDebugEnabled()) { LOG.debug("Call: "+method.getName()+", "+(args != null ? args.length : 0)); } if (row != null) { final Exec exec = new Exec(conf, row, protocol, method, args); ServerCallable<ExecResult> callable = new ServerCallable<ExecResult>(connection, table, row) { public ExecResult call() throws Exception { return server.execCoprocessor(location.getRegionInfo().getRegionName(), exec); } }; ExecResult result = callable.withRetries(); this.regionName = result.getRegionName(); LOG.debug("Result is region="+ Bytes.toStringBinary(regionName) + ", value="+result.getValue()); return result.getValue(); } return null; }
@Test public void testExecDeserialization() throws IOException { DataOutputBuffer dob = new DataOutputBuffer(); dob.writeUTF(methodName); dob.writeInt(1); Scan scan = new Scan(); HbaseObjectWritable.writeObject(dob, scan, Scan.class, new Configuration()); dob.writeUTF("org.apache.hadoop.hbase.client.Scan"); Bytes.writeByteArray(dob, new byte[]{'a'}); // this is the dynamic protocol name dob.writeUTF(protocolName); DataInputBuffer dib = new DataInputBuffer(); dib.reset(dob.getData(), dob.getLength()); Exec after = new Exec(); after.setConf(HBaseConfiguration.create()); after.readFields(dib); // no error thrown assertEquals(after.getProtocolName(), protocolName); assertEquals(after.getMethodName(), methodName); }
@Override public Object invoke(Object instance, final Method method, final Object[] args) throws Throwable { if (LOG.isDebugEnabled()) { LOG.debug("Call: "+method.getName()+", "+(args != null ? args.length : 0)); } if (row != null) { final Exec exec = new Exec(conf, row, protocol, method, args); ServerCallable<ExecResult> callable = new ServerCallable<ExecResult>(connection, table, row) { public ExecResult call() throws Exception { return server.execCoprocessor(location.getRegionInfo().getRegionName(), exec); } }; ExecResult result = connection.getRegionServerWithRetries(callable); this.regionName = result.getRegionName(); LOG.debug("Result is region="+ Bytes.toStringBinary(regionName) + ", value="+result.getValue()); return result.getValue(); } return null; }
@Override public Object invoke(Object instance, final Method method, final Object[] args) throws Throwable { if (LOG.isDebugEnabled()) { LOG.debug("Call: "+method.getName()+", "+(args != null ? args.length : 0)); } Exec exec = new Exec(conf, protocol, method, args); ExecResult result = connection.getMaster().execCoprocessor(exec); LOG.debug("Master Result is value="+result.getValue()); return result.getValue(); }
/** * Executes a single {@link org.apache.hadoop.hbase.ipc.CoprocessorProtocol} method using the * registered protocol handlers. {@link CoprocessorProtocol} implementations must be registered * per-region via the * {@link org.apache.hadoop.hbase.regionserver.HRegion#registerProtocol(Class, org.apache.hadoop.hbase.ipc.CoprocessorProtocol)} * method before they are available. * @param regionName name of the region against which the invocation is executed * @param call an {@code Exec} instance identifying the protocol, method name, and parameters for * the method invocation * @return an {@code ExecResult} instance containing the region name of the invocation and the * return value * @throws IOException if no registered protocol handler is found or an error occurs during the * invocation * @see org.apache.hadoop.hbase.regionserver.HRegion#registerProtocol(Class, * org.apache.hadoop.hbase.ipc.CoprocessorProtocol) */ @Override public ExecResult execCoprocessor(byte[] regionName, Exec call) throws IOException { checkOpen(); requestCount.incrementAndGet(); try { HRegion region = getRegion(regionName); return region.exec(call); } catch (Throwable t) { throw convertThrowableToIOE(cleanup(t)); } }
/** * Executes a single {@link org.apache.hadoop.hbase.ipc.CoprocessorProtocol} * method using the registered protocol handlers. * {@link CoprocessorProtocol} implementations must be registered per-region * via the * {@link org.apache.hadoop.hbase.regionserver.HRegion#registerProtocol(Class, org.apache.hadoop.hbase.ipc.CoprocessorProtocol)} * method before they are available. * * @param regionName name of the region against which the invocation is executed * @param call an {@code Exec} instance identifying the protocol, method name, * and parameters for the method invocation * @return an {@code ExecResult} instance containing the region name of the * invocation and the return value * @throws IOException if no registered protocol handler is found or an error * occurs during the invocation * @see org.apache.hadoop.hbase.regionserver.HRegion#registerProtocol(Class, org.apache.hadoop.hbase.ipc.CoprocessorProtocol) */ @Override public ExecResult execCoprocessor(byte[] regionName, Exec call) throws IOException { checkOpen(); requestCount.incrementAndGet(); try { HRegion region = getRegion(regionName); return region.exec(call); } catch (Throwable t) { throw convertThrowableToIOE(cleanup(t)); } }
/** * Executes a single {@link org.apache.hadoop.hbase.ipc.CoprocessorProtocol} * method using the registered protocol handlers. * {@link CoprocessorProtocol} implementations must be registered via the * {@link org.apache.hadoop.hbase.master.MasterServices#registerProtocol(Class, CoprocessorProtocol)} * method before they are available. * * @param call an {@code Exec} instance identifying the protocol, method name, * and parameters for the method invocation * @return an {@code ExecResult} instance containing the region name of the * invocation and the return value * @throws IOException if no registered protocol handler is found or an error * occurs during the invocation * @see org.apache.hadoop.hbase.master.MasterServices#registerProtocol(Class, CoprocessorProtocol) */ public ExecResult execCoprocessor(Exec call) throws IOException;
/** * Executes a single {@link org.apache.hadoop.hbase.ipc.CoprocessorProtocol} * method using the registered protocol handlers. * {@link CoprocessorProtocol} implementations must be registered via the * {@link org.apache.hadoop.hbase.regionserver.HRegion#registerProtocol(Class, org.apache.hadoop.hbase.ipc.CoprocessorProtocol)} * method before they are available. * * @param regionName name of the region against which the invocation is executed * @param call an {@code Exec} instance identifying the protocol, method name, * and parameters for the method invocation * @return an {@code ExecResult} instance containing the region name of the * invocation and the return value * @throws IOException if no registered protocol handler is found or an error * occurs during the invocation * @see org.apache.hadoop.hbase.regionserver.HRegion#registerProtocol(Class, org.apache.hadoop.hbase.ipc.CoprocessorProtocol) */ ExecResult execCoprocessor(byte[] regionName, Exec call) throws IOException;