[ 
https://issues.apache.org/jira/browse/HIVE-12777?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15112357#comment-15112357
 ] 

Rajat Khandelwal commented on HIVE-12777:
-----------------------------------------

[~xuefuz] I'll try to answer as clearly as possible using an example. 

Imagine a piece of code that uses SessionHandle as a member of a class. For 
convenience it takes CLIService in the constructor so that it can create the 
session handle. 

{noformat}
public class Blah{
        public CLIService cliService;
        SessionHandle handle;
        public Blah(CLIService cliService){
                this.cliService = cliService;
                this.session = cliService.openSession(...);
        }
}
{noformat}

Now, imagine that Blah is an important part of a big project. The project has a 
server like architecture and has capabilities for stop/start/restart. 
CLIService is something it's creating in its lifecycle somewhere. 

Now, the project needs the capability to get an instance of Blah class that it 
had created before one restart. It has control over Blah objects so it has 
logic to serialize/deserialize Blah objects. Let's say that the server is able 
to read SessionHandle on restart and needs to create Blah objects using that. 

Looking at our code so far, this use case is not supported. Hence we add a 
constructor 

{noformat}
public class Blah{
        public CLIService cliService;
        SessionHandle handle;
        public Blah(CLIService cliService){
                this.cliService = cliService;
                this.session = cliService.openSession(...);
        }
        public Blah(CLIService cliService, SessionHandle session){
                this.cliService = cliService;
                this.session = session;
        }
}
{noformat}

But that's not enough. Suppose the server had crashed. On restart, it'll create 
a new instance of CLIService, and as a side effect, a new Session Manager. 
(Remember, there is no involvement of HiveServer) The new session manager 
doesn't recognize the old session. Hence, two additions are necessary:

{noformat}
public class SessionManager{
        ...
        public SessionHandle restoreSession(...){
                ...
        }
        ...
}

public class CLIService{
        ...
        public SessionHandle restoreSession(...){
                sessionManager.restoreSession(...)
        }
        ...
}
{noformat}

so that Blah class can do this for completeness:

{noformat}
public class Blah{
        public CLIService cliService;
        SessionHandle handle;
        public Blah(CLIService cliService){
                this.cliService = cliService;
                this.session = cliService.openSession(...);
        }
        public Blah(CLIService cliService, SessionHandle session){
                this.cliService = cliService;           
                this.session = cliService.restoreSession(session, ...)
        }
}
{noformat}

The required additions(last but one) are the changes I've posted in the review 
request and patch. 

To re-iterate, this is not a Hive Server feature, but just a feature in 
CLIService. CLIService needs a capability to restore a session.

bq. Are we trying to restore a session that's lost? How does it get lost?

Yes, JVM crash caused the session to get lost. 

bq. Where do we restore it from?
The user of CLIService restores it from whatever persistence it has, and asks 
CLIService to do necessary book keeping for restoring.

bq. How does this benefits Hive users?
Don't know about Hive users per se, but the applications depending on hive -- 
in particular CLIService -- get the benefit of maintaining the same session on 
unexpected scenarios, whereas without this feature they'll have to do extensive 
bookkeeping for maintaining the list of session handles that were used while 
performing a sequence of operations. 



> Add capability to restore session
> ---------------------------------
>
>                 Key: HIVE-12777
>                 URL: https://issues.apache.org/jira/browse/HIVE-12777
>             Project: Hive
>          Issue Type: Improvement
>            Reporter: Rajat Khandelwal
>            Assignee: Rajat Khandelwal
>         Attachments: HIVE-12777.04.patch, HIVE-12777.08.patch, 
> HIVE-12777.09.patch, HIVE-12777.11.patch, HIVE-12777.12.patch, 
> HIVE-12777.13.patch, HIVE-12777.15.patch, HIVE-12777.16.patch, 
> HIVE-12777.17.patch
>
>
> Extensions using Hive session handles should be able to restore the hive 
> session from the handle. 
> Apache Lens depends on a fork of hive and that fork has such a capability. 
> Relevant commit: 
> https://github.com/InMobi/hive/commit/931fe9116161a18952c082c14223ad6745fefe00#diff-0acb35f7cab7492f522b0c40ce3ce1be
> Functionality added: Restoring a session. A session opened once is lost once 
> the cli service is restarted. There may be some operation going on in that 
> session at the time the service is restarted. It's useful to be able to 
> restore a previously existing session. 
> Have added code in CLIService for that effect. Have also added a test class. 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to