Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KYUUBI #1948] Upgrade thrift version to 0.16.0
### _Why are the changes needed?_ Upgrade libthrift to 0.16.0 due to [CVE-2020-13949](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-13949) and the coming upstream change of Spark apache/spark#34362 ### _What changed in this PR?_ - Upgrade libthrift to 0.16.0 - Shade and relocate `thrift` and `hive-service-rpc` classes in `kyuubi-spark-engine`, it's necessary to avoide conflicting with old thrift libs bundled in Spark binary releases. - Due to thrift change the method signature, the subclasses those interfaces in Kyuubi also need to modify to pass compile. We rely on Hive 2.3.9 jars in some components, e.g. `kyuubi-hive-jdbc`, `LocalMetaServer` in `kyuubi-server` test classes. Some classes in Hive jars compiled against old thrift interfaces which are not compatible with thrift 0.16.0, it causes runtime link error, we found the following classes which breaks the test and copied them with necessary modification to make it work with thrift 0.16.0. - `TFramedTransport` - `TFilterTransport` - `TUGIAssumingTransport` - `TUGIContainingTransport` - Next Steps, I think it's worth to do in separated PRs. - Recover the `HiveDelegationTokenProviderSuite`, one approach is use an isolate classloader to load HMS classes and thrift 0.9.3 classes from Maven, this approach can also be used for the planed Zoopkeeper upgrading to help us verficating the compatibility of Zookeeper Server 3.4.x. - Rewrite `kyuubi-hive-jdbc` to make it decouple with Hive jars, because there maybe other places which may not work with thrift 0.16.0 but the UTs does not cover. ### _How was this patch tested?_ - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [ ] Add screenshots for manual tests if appropriate - [x] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #1953 from SteNicholas/KYUUBI-1948. Closes #1948 de5d1ea [SteNicholas] [KYUUBI #1948] Upgrade thrift version to 0.16.0 898effc [SteNicholas] [KYUUBI #1948] Upgrade thrift version to 0.16.0 803e270 [SteNicholas] [KYUUBI #1948] Upgrade thrift version to 0.16.0 Authored-by: SteNicholas <programgeek@163.com> Signed-off-by: Kent Yao <yao@apache.org>
- Loading branch information
1 parent
de14958
commit 770499c
Showing
26 changed files
with
1,478 additions
and
67 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
185 changes: 185 additions & 0 deletions
185
...yuubi-extension-spark-3-1/src/test/java/org/apache/thrift/transport/TFramedTransport.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,185 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.thrift.transport; | ||
|
||
import org.apache.thrift.TByteArrayOutputStream; | ||
import org.apache.thrift.TConfiguration; | ||
|
||
/** | ||
* This is based on libthrift-0.12.0 {@link TFramedTransport}. To fix class of | ||
* org.apache.thrift.transport.TFramedTransport not found after upgrading libthrift. | ||
* | ||
* <p>TFramedTransport is a buffered TTransport that ensures a fully read message every time by | ||
* preceding messages with a 4-byte frame size. | ||
*/ | ||
public class TFramedTransport extends TTransport { | ||
|
||
protected static final int DEFAULT_MAX_LENGTH = 16384000; | ||
|
||
private int maxLength_; | ||
|
||
/** Underlying transport */ | ||
private TTransport transport_ = null; | ||
|
||
/** Buffer for output */ | ||
private final TByteArrayOutputStream writeBuffer_ = new TByteArrayOutputStream(1024); | ||
|
||
/** Buffer for input */ | ||
private final TMemoryInputTransport readBuffer_ = new TMemoryInputTransport(new byte[0]); | ||
|
||
public static class Factory extends TTransportFactory { | ||
private int maxLength_; | ||
|
||
public Factory() { | ||
maxLength_ = TFramedTransport.DEFAULT_MAX_LENGTH; | ||
} | ||
|
||
public Factory(int maxLength) { | ||
maxLength_ = maxLength; | ||
} | ||
|
||
@Override | ||
public TTransport getTransport(TTransport base) throws TTransportException { | ||
return new TFramedTransport(base, maxLength_); | ||
} | ||
} | ||
|
||
/** Constructor wraps around another transport */ | ||
public TFramedTransport(TTransport transport, int maxLength) throws TTransportException { | ||
transport_ = transport; | ||
maxLength_ = maxLength; | ||
} | ||
|
||
public TFramedTransport(TTransport transport) throws TTransportException { | ||
transport_ = transport; | ||
maxLength_ = TFramedTransport.DEFAULT_MAX_LENGTH; | ||
} | ||
|
||
public void open() throws TTransportException { | ||
transport_.open(); | ||
} | ||
|
||
public boolean isOpen() { | ||
return transport_.isOpen(); | ||
} | ||
|
||
public void close() { | ||
transport_.close(); | ||
} | ||
|
||
public int read(byte[] buf, int off, int len) throws TTransportException { | ||
int got = readBuffer_.read(buf, off, len); | ||
if (got > 0) { | ||
return got; | ||
} | ||
|
||
// Read another frame of data | ||
readFrame(); | ||
|
||
return readBuffer_.read(buf, off, len); | ||
} | ||
|
||
@Override | ||
public byte[] getBuffer() { | ||
return readBuffer_.getBuffer(); | ||
} | ||
|
||
@Override | ||
public int getBufferPosition() { | ||
return readBuffer_.getBufferPosition(); | ||
} | ||
|
||
@Override | ||
public int getBytesRemainingInBuffer() { | ||
return readBuffer_.getBytesRemainingInBuffer(); | ||
} | ||
|
||
@Override | ||
public void consumeBuffer(int len) { | ||
readBuffer_.consumeBuffer(len); | ||
} | ||
|
||
@Override | ||
public TConfiguration getConfiguration() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void updateKnownMessageSize(long l) throws TTransportException {} | ||
|
||
@Override | ||
public void checkReadBytesAvailable(long l) throws TTransportException {} | ||
|
||
public void clear() { | ||
readBuffer_.clear(); | ||
} | ||
|
||
private final byte[] i32buf = new byte[4]; | ||
|
||
private void readFrame() throws TTransportException { | ||
transport_.readAll(i32buf, 0, 4); | ||
int size = decodeFrameSize(i32buf); | ||
|
||
if (size < 0) { | ||
close(); | ||
throw new TTransportException( | ||
TTransportException.CORRUPTED_DATA, "Read a negative frame size (" + size + ")!"); | ||
} | ||
|
||
if (size > maxLength_) { | ||
close(); | ||
throw new TTransportException( | ||
TTransportException.CORRUPTED_DATA, | ||
"Frame size (" + size + ") larger than max length (" + maxLength_ + ")!"); | ||
} | ||
|
||
byte[] buff = new byte[size]; | ||
transport_.readAll(buff, 0, size); | ||
readBuffer_.reset(buff); | ||
} | ||
|
||
public void write(byte[] buf, int off, int len) throws TTransportException { | ||
writeBuffer_.write(buf, off, len); | ||
} | ||
|
||
@Override | ||
public void flush() throws TTransportException { | ||
byte[] buf = writeBuffer_.get(); | ||
int len = writeBuffer_.len(); | ||
writeBuffer_.reset(); | ||
|
||
encodeFrameSize(len, i32buf); | ||
transport_.write(i32buf, 0, 4); | ||
transport_.write(buf, 0, len); | ||
transport_.flush(); | ||
} | ||
|
||
public static final void encodeFrameSize(final int frameSize, final byte[] buf) { | ||
buf[0] = (byte) (0xff & (frameSize >> 24)); | ||
buf[1] = (byte) (0xff & (frameSize >> 16)); | ||
buf[2] = (byte) (0xff & (frameSize >> 8)); | ||
buf[3] = (byte) (0xff & (frameSize)); | ||
} | ||
|
||
public static final int decodeFrameSize(final byte[] buf) { | ||
return ((buf[0] & 0xff) << 24) | ||
| ((buf[1] & 0xff) << 16) | ||
| ((buf[2] & 0xff) << 8) | ||
| ((buf[3] & 0xff)); | ||
} | ||
} |
185 changes: 185 additions & 0 deletions
185
...yuubi-extension-spark-3-2/src/test/java/org/apache/thrift/transport/TFramedTransport.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,185 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.thrift.transport; | ||
|
||
import org.apache.thrift.TByteArrayOutputStream; | ||
import org.apache.thrift.TConfiguration; | ||
|
||
/** | ||
* This is based on libthrift-0.12.0 {@link TFramedTransport}. To fix class of | ||
* org.apache.thrift.transport.TFramedTransport not found after upgrading libthrift. | ||
* | ||
* <p>TFramedTransport is a buffered TTransport that ensures a fully read message every time by | ||
* preceding messages with a 4-byte frame size. | ||
*/ | ||
public class TFramedTransport extends TTransport { | ||
|
||
protected static final int DEFAULT_MAX_LENGTH = 16384000; | ||
|
||
private int maxLength_; | ||
|
||
/** Underlying transport */ | ||
private TTransport transport_ = null; | ||
|
||
/** Buffer for output */ | ||
private final TByteArrayOutputStream writeBuffer_ = new TByteArrayOutputStream(1024); | ||
|
||
/** Buffer for input */ | ||
private final TMemoryInputTransport readBuffer_ = new TMemoryInputTransport(new byte[0]); | ||
|
||
public static class Factory extends TTransportFactory { | ||
private int maxLength_; | ||
|
||
public Factory() { | ||
maxLength_ = TFramedTransport.DEFAULT_MAX_LENGTH; | ||
} | ||
|
||
public Factory(int maxLength) { | ||
maxLength_ = maxLength; | ||
} | ||
|
||
@Override | ||
public TTransport getTransport(TTransport base) throws TTransportException { | ||
return new TFramedTransport(base, maxLength_); | ||
} | ||
} | ||
|
||
/** Constructor wraps around another transport */ | ||
public TFramedTransport(TTransport transport, int maxLength) throws TTransportException { | ||
transport_ = transport; | ||
maxLength_ = maxLength; | ||
} | ||
|
||
public TFramedTransport(TTransport transport) throws TTransportException { | ||
transport_ = transport; | ||
maxLength_ = TFramedTransport.DEFAULT_MAX_LENGTH; | ||
} | ||
|
||
public void open() throws TTransportException { | ||
transport_.open(); | ||
} | ||
|
||
public boolean isOpen() { | ||
return transport_.isOpen(); | ||
} | ||
|
||
public void close() { | ||
transport_.close(); | ||
} | ||
|
||
public int read(byte[] buf, int off, int len) throws TTransportException { | ||
int got = readBuffer_.read(buf, off, len); | ||
if (got > 0) { | ||
return got; | ||
} | ||
|
||
// Read another frame of data | ||
readFrame(); | ||
|
||
return readBuffer_.read(buf, off, len); | ||
} | ||
|
||
@Override | ||
public byte[] getBuffer() { | ||
return readBuffer_.getBuffer(); | ||
} | ||
|
||
@Override | ||
public int getBufferPosition() { | ||
return readBuffer_.getBufferPosition(); | ||
} | ||
|
||
@Override | ||
public int getBytesRemainingInBuffer() { | ||
return readBuffer_.getBytesRemainingInBuffer(); | ||
} | ||
|
||
@Override | ||
public void consumeBuffer(int len) { | ||
readBuffer_.consumeBuffer(len); | ||
} | ||
|
||
@Override | ||
public TConfiguration getConfiguration() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void updateKnownMessageSize(long l) throws TTransportException {} | ||
|
||
@Override | ||
public void checkReadBytesAvailable(long l) throws TTransportException {} | ||
|
||
public void clear() { | ||
readBuffer_.clear(); | ||
} | ||
|
||
private final byte[] i32buf = new byte[4]; | ||
|
||
private void readFrame() throws TTransportException { | ||
transport_.readAll(i32buf, 0, 4); | ||
int size = decodeFrameSize(i32buf); | ||
|
||
if (size < 0) { | ||
close(); | ||
throw new TTransportException( | ||
TTransportException.CORRUPTED_DATA, "Read a negative frame size (" + size + ")!"); | ||
} | ||
|
||
if (size > maxLength_) { | ||
close(); | ||
throw new TTransportException( | ||
TTransportException.CORRUPTED_DATA, | ||
"Frame size (" + size + ") larger than max length (" + maxLength_ + ")!"); | ||
} | ||
|
||
byte[] buff = new byte[size]; | ||
transport_.readAll(buff, 0, size); | ||
readBuffer_.reset(buff); | ||
} | ||
|
||
public void write(byte[] buf, int off, int len) throws TTransportException { | ||
writeBuffer_.write(buf, off, len); | ||
} | ||
|
||
@Override | ||
public void flush() throws TTransportException { | ||
byte[] buf = writeBuffer_.get(); | ||
int len = writeBuffer_.len(); | ||
writeBuffer_.reset(); | ||
|
||
encodeFrameSize(len, i32buf); | ||
transport_.write(i32buf, 0, 4); | ||
transport_.write(buf, 0, len); | ||
transport_.flush(); | ||
} | ||
|
||
public static final void encodeFrameSize(final int frameSize, final byte[] buf) { | ||
buf[0] = (byte) (0xff & (frameSize >> 24)); | ||
buf[1] = (byte) (0xff & (frameSize >> 16)); | ||
buf[2] = (byte) (0xff & (frameSize >> 8)); | ||
buf[3] = (byte) (0xff & (frameSize)); | ||
} | ||
|
||
public static final int decodeFrameSize(final byte[] buf) { | ||
return ((buf[0] & 0xff) << 24) | ||
| ((buf[1] & 0xff) << 16) | ||
| ((buf[2] & 0xff) << 8) | ||
| ((buf[3] & 0xff)); | ||
} | ||
} |
Oops, something went wrong.