Skip to content

DRILL-5485: Remove WebServer dependency on DrillClient#829

Closed
sohami wants to merge 4 commits intoapache:masterfrom
sohami:DRILL-5485
Closed

DRILL-5485: Remove WebServer dependency on DrillClient#829
sohami wants to merge 4 commits intoapache:masterfrom
sohami:DRILL-5485

Conversation

@sohami
Copy link
Contributor

@sohami sohami commented May 10, 2017

No description provided.

@sohami sohami force-pushed the DRILL-5485 branch 2 times, most recently from d90af9e to 503f861 Compare May 20, 2017 04:03
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public abstract class AbstractUserClientConnectionWrapper implements UserClientConnection {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some doc about how instances of sub-classes can only be used once.

And this classes itself doesn't wrap.. How about AbstractDisposableUserClientConnection?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed.

* @param listener
* @param result
*/
void sendResult(RpcOutcomeListener<GeneralRPCProtos.Ack> listener, UserBitShared.QueryResult result);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add imports for inner classes, here and everywhere else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not fixed?

.setUserName(sessionUserPrincipal.getName())
.build())
.withOptionManager(drillbitContext.getOptionManager())
.setSupportComplexTypes(drillbitContext.getConfig().getBoolean(ExecConstants.CLIENT_SUPPORT_COMPLEX_TYPES))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used to check if client can handle complex types, which is not based on config. Can the web client handle complex types?

Similar call below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For DrillClient by default this is set as true based on the config only. I looked into the usage and based on this property in session, if false planner will introduce a project node to convert complex types to JSON string. On WebServer when data batch is received we convert each data type to it's string format (even the complex types). Hence it does support complex types since WebClient now will see all the data in Json string format and should be fine.

public UserBitShared.QueryType getType() {
UserBitShared.QueryType type = UserBitShared.QueryType.SQL;
public QueryType getType() {
QueryType type = QueryType.SQL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return QueryType.valueOf(queryType);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

}
public QueryResult run(final WorkManager workManager, final WebUserConnection webUserConnection) throws Exception {

final UserProtos.RunQuery runQuery = UserProtos.RunQuery.getDefaultInstance().newBuilderForType()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RunQuery.newBuilder().setType(...)...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

try {
// This can be slow as the underlying library will try to resolve the address
remoteAddress = new InetSocketAddress(InetAddress.getByName(request.getRemoteAddr()), request.getRemotePort());
session.setAttribute(SocketAddress.class.getSimpleName(), remoteAddress);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attributes names too generic. Maybe use: "drill-user-session", "drill-socket-address", ...?


/**
* For anonymous WebUserSession it is called after each query request whereas for Authenticated WebUserSession
* it is never called.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment does not seem right. Looks to me that cleanupSession() is called after every query request, and the session resources are closed iff the user is anonymous.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelFuture;
import static org.apache.drill.exec.ExecConstants.CREATE_PREPARE_STATEMENT_TIMEOUT_MILLIS;
import static org.apache.drill.exec.proto.UserProtos.RequestStatus.*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expand imports

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

return new SessionHandler(sessionManager);
}

private void clearSessionCustomAttributes(HttpSession session) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about encapsulating all the resources in one class (DrillWebSession)?

  • Only that instance would be an attribute on a http session.
  • This logic could be captured in DrillWebSession#close method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WebUserConnection is a class which is encapsulating all the resources. I had the logic of close and cleanup in it earlier. But I Didn't set that as attribute of Http session object since in that case it will be reset for each request. Since there are not many resources which we are setting inside HttpSession and each of them are really a separate property for the session in itself, I guess keeping them separated should be fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I somehow managed to delete this in my comment..) The life cycle of those resources could be placed together in one class, as resources are being initialized in one place but closed in different places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved all the resources inside another class WebSessionResources which now manages their lifecycle.

public class WebUserConnection extends AbstractUserClientConnectionWrapper implements ConnectionThrottle {
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(WebUserConnection.class);

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class level doc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Sorabh Hamirwasia added 3 commits May 24, 2017 00:45
…roviders for Authenticated and Anonymous web users.

	NOTE: Updated to store the UserSession, BufferAllocator and other session states inside the HttpSession of Jetty instead
              of storing in DrillUserPrincipal. For each request now a new instance of WebUserConnection will be created. However
              for authenticated users the UserSession and other states will be re-used whereas for Anonymous Users it will created
              for each request and later re-cycled after query execution.
@jinfengni
Copy link
Contributor

Seems @sohami has addressed @sudheeshkatkam 's comments. I'm going to merge this PR.

+1

jinfengni pushed a commit to jinfengni/incubator-drill that referenced this pull request Jun 1, 2017
1. Added WebUserConnection/AnonWebUserConnection and their providers for Authenticated and Anonymous web users.
2. Updated to store the UserSession, BufferAllocator and other session states inside the HttpSession of Jetty instead
	of storing in DrillUserPrincipal. For each request now a new instance of WebUserConnection will be created. However
	for authenticated users the UserSession and other states will be re-used whereas for Anonymous Users it will created
	for each request and later re-cycled after query execution.

close apache#829
@asfgit asfgit closed this in 874bf62 Jun 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants