-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added extra option to add readOnly thrift HMS uri (#308)
* Added extra option to add readOnly thrift HMS uri which will be called on read only calls for better spread of traffic
- Loading branch information
Patrick Duin
authored
Feb 8, 2024
1 parent
f6520ea
commit 19f57a5
Showing
22 changed files
with
318 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...e/src/main/java/com/hotels/bdp/waggledance/client/SplitTrafficMetastoreClientFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* Copyright (C) 2016-2024 Expedia, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.hotels.bdp.waggledance.client; | ||
|
||
import java.lang.reflect.InvocationHandler; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Proxy; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* This class splits the traffic for read only calls (get* for instance getTable, getPartition) to the readOnly client | ||
* and everything else will go to readWrite client. | ||
*/ | ||
public class SplitTrafficMetastoreClientFactory { | ||
|
||
static final Class<?>[] INTERFACES = new Class<?>[] { CloseableThriftHiveMetastoreIface.class }; | ||
|
||
private static class SplitTrafficClientInvocationHandler implements InvocationHandler { | ||
|
||
private static Logger log = LoggerFactory | ||
.getLogger(SplitTrafficMetastoreClientFactory.SplitTrafficClientInvocationHandler.class); | ||
|
||
private final CloseableThriftHiveMetastoreIface readWrite; | ||
private final CloseableThriftHiveMetastoreIface readOnly; | ||
|
||
public SplitTrafficClientInvocationHandler( | ||
CloseableThriftHiveMetastoreIface readWrite, | ||
CloseableThriftHiveMetastoreIface readOnly) { | ||
this.readWrite = readWrite; | ||
this.readOnly = readOnly; | ||
} | ||
|
||
@Override | ||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { | ||
switch (method.getName()) { | ||
case "isOpen": | ||
return readWrite.isOpen() && readOnly.isOpen(); | ||
case "close": | ||
try { | ||
readWrite.close(); | ||
} finally { | ||
readOnly.close(); | ||
} | ||
return null; | ||
case "set_ugi": | ||
Object result = doRealCall(readWrite, method, args); | ||
// we skip the result for readOnly (it should always be the same). | ||
doRealCall(readOnly, method, args); | ||
return result; | ||
default: | ||
if (method.getName().startsWith("get")) { | ||
log.info("Calling {}.{}", "readOnly", method.getName()); | ||
return doRealCall(readOnly, method, args); | ||
} | ||
log.info("Calling {}.{}", "readWrite", method.getName()); | ||
return doRealCall(readWrite, method, args); | ||
} | ||
} | ||
|
||
private Object doRealCall(CloseableThriftHiveMetastoreIface client, Method method, Object[] args) | ||
throws IllegalAccessException, Throwable { | ||
try { | ||
return method.invoke(client, args); | ||
} catch (InvocationTargetException e) { | ||
Throwable realException = e.getTargetException(); | ||
throw realException; | ||
} | ||
} | ||
} | ||
|
||
public CloseableThriftHiveMetastoreIface newInstance( | ||
CloseableThriftHiveMetastoreIface readWrite, | ||
CloseableThriftHiveMetastoreIface readOnly) { | ||
return (CloseableThriftHiveMetastoreIface) Proxy | ||
.newProxyInstance(getClass().getClassLoader(), INTERFACES, | ||
new SplitTrafficClientInvocationHandler(readWrite, readOnly)); | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...e-core/src/main/java/com/hotels/bdp/waggledance/client/adapter/MetastoreIfaceAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...s/bdp/waggledance/client/compatibility/HiveCompatibleThriftHiveMetastoreIfaceFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/server/FederatedHMSHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.