Hi, all,

I am trying to learn how to share data between two coprocessors. I have one 
Observer coprocessor and one Endpoint coprocessor. In the observer, it overload 
the prePut/preDelete to maintain a counter. And I want the Endpoint coprocessor 
to read that counter and return to client caller. So I want to use the 
getSharedData() method in RegionCoprocessorEnvironment, but I cannot make it 
work. Could anybody help me here?

In the Observer Coprocessor :
During start(), create the shared object "counter":
-----------------------------------------------------------------
public void start(CoprocessorEnvironment envi) throws IOException {
  Env.getSharedData().put("counter", new Long(0) ); //create the counter
-----------------------------------------------------------------

In the Endpoint coprocessor:
During start(), try to read the shared "counter" , but failed.
------------------------------------------------------------------
public void start(CoprocessorEnvironment envi) throws IOException {
     LOG.info("The size of sharedData map is: " + envi.getSharedData().size() 
); //try to get the counter
------------------------------------------------------------------
Here it print 0, if I use evni.getSharedData().containsKey("counter"), it will 
return false.

When creating table, I call addCoprocessor() method to add Observer first, then 
Endpoint coprocessor. I confirmed that by checking the hbase log file message. 
I only have one region for that table during the run. I confirmed by hbase 
shell status 'detailed' command.

There is not much example I can find about how to use getSharedData(), could 
someone help me here? What is missing in my simple code? Thanks very much in 
advance!

Thanks,
Ming

Reply via email to