Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HBase PrivilegedExceptionAction runAs thread?

I have HBase code that I use for gets (Although I don't have Kerberos on, I plan to have it later so I wanted to make sure that user credentials were handled correctly when connecting and doing a Put or Get).

final ByteArrayOutputStream bos = new ByteArrayOutputStream();
MyHBaseService.getUserHBase().runAs(new PrivilegedExceptionAction<Object>() {
                @Override
                public Object run() throws Exception {
                    Connection connection = null;
                    Table StorageTable = null;
                    List<hFile> HbaseDownload = new ArrayList<>();
                    try {
                        // Open an HBase Connection
                        connection = ConnectionFactory.createConnection(MyHBaseService.getHBaseConfiguration());
                     Get get = new Get(Bytes.toBytes("filenameCell"));
                     Result result = table.get(get);
                     byte[] data = result.getValue(Bytes.toBytes(MyHBaseService.getDataStoreFamily()), Bytes.toBytes(MyHBaseService.getDataStoreQualifier()));
                     bos.write(data, 0, data.length);
                     bos.flush();
                     ...
                }
          });
          // now get the outputstream.
          // I am assuming byteArrayStream is synchronized and thread-safe.
          return bos.toByteArray();

However, I wasn't sure if this was running an asynchronous or synchronous thread.

The problem:

I use:

Get get = new Get(Bytes.toBytes("filenameCell"));
                Result result = table.get(get);

Inside this run() function. But to get information OUT of the run() thread I use a new ByteOutputArrayStream OUTSIDE the run(). ByteOutputArrayStream.write & ByteOutputArrayStream.flush inside the run(). Then toByteArray() to get the binary bytes of the HBase content out of the function. This causes null bytes to be returned though, so maybe I'm not doing this right.

However, I am having difficulty finding good examples of HBase Java API to do these things and no one seems to use runAs like I do. It's so strange.

I have HBase 1.2.5 client running inside a Web App (request-based function calls).

like image 690
Dexter Avatar asked Nov 07 '22 08:11

Dexter


1 Answers

Here in this code the thread is running inside "MyHBaseService.getUserHBase().runAs" this. But if it is running asyncronously then before executing it properly program will return "bos.toByteArray();" as this is outside the runAs(). So before even executing the complete function it will return the output.

I think thats the reason of null values.

like image 100
Naresh Bharadwaj Avatar answered Nov 15 '22 12:11

Naresh Bharadwaj