diff --git a/dev/dependencyList b/dev/dependencyList index 3bb9e6e5df2..c42ee23cada 100644 --- a/dev/dependencyList +++ b/dev/dependencyList @@ -36,6 +36,8 @@ hk2-api/2.6.1//hk2-api-2.6.1.jar hk2-locator/2.6.1//hk2-locator-2.6.1.jar hk2-utils/2.6.1//hk2-utils-2.6.1.jar htrace-core4/4.1.0-incubating//htrace-core4-4.1.0-incubating.jar +httpclient/4.5.13//httpclient-4.5.13.jar +httpcore/4.4.15//httpcore-4.4.15.jar jackson-annotations/2.13.1//jackson-annotations-2.13.1.jar jackson-core/2.13.1//jackson-core-2.13.1.jar jackson-databind/2.13.1//jackson-databind-2.13.1.jar @@ -70,7 +72,7 @@ jetty-util-ajax/9.4.41.v20210516//jetty-util-ajax-9.4.41.v20210516.jar jetty-util/9.4.41.v20210516//jetty-util-9.4.41.v20210516.jar jline/0.9.94//jline-0.9.94.jar libfb303/0.9.3//libfb303-0.9.3.jar -libthrift/0.9.3//libthrift-0.9.3.jar +libthrift/0.16.0//libthrift-0.16.0.jar log4j-1.2-api/2.17.1//log4j-1.2-api-2.17.1.jar log4j-api/2.17.1//log4j-api-2.17.1.jar log4j-core/2.17.1//log4j-core-2.17.1.jar diff --git a/dev/kyuubi-extension-spark-3-1/src/test/java/org/apache/thrift/transport/TFramedTransport.java b/dev/kyuubi-extension-spark-3-1/src/test/java/org/apache/thrift/transport/TFramedTransport.java new file mode 100644 index 00000000000..3777218efcf --- /dev/null +++ b/dev/kyuubi-extension-spark-3-1/src/test/java/org/apache/thrift/transport/TFramedTransport.java @@ -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. + * + *

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)); + } +} diff --git a/dev/kyuubi-extension-spark-3-2/src/test/java/org/apache/thrift/transport/TFramedTransport.java b/dev/kyuubi-extension-spark-3-2/src/test/java/org/apache/thrift/transport/TFramedTransport.java new file mode 100644 index 00000000000..3777218efcf --- /dev/null +++ b/dev/kyuubi-extension-spark-3-2/src/test/java/org/apache/thrift/transport/TFramedTransport.java @@ -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. + * + *

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)); + } +} diff --git a/dev/kyuubi-extension-spark-common/src/test/java/org/apache/thrift/transport/TFramedTransport.java b/dev/kyuubi-extension-spark-common/src/test/java/org/apache/thrift/transport/TFramedTransport.java new file mode 100644 index 00000000000..3777218efcf --- /dev/null +++ b/dev/kyuubi-extension-spark-common/src/test/java/org/apache/thrift/transport/TFramedTransport.java @@ -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. + * + *

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)); + } +} diff --git a/docs/deployment/settings.md b/docs/deployment/settings.md index 4224f63905b..c9592694de0 100644 --- a/docs/deployment/settings.md +++ b/docs/deployment/settings.md @@ -211,11 +211,9 @@ Key | Default | Meaning | Type | Since Key | Default | Meaning | Type | Since --- | --- | --- | --- | --- -kyuubi.frontend.backoff.slot.length|

PT0.1S
|
(deprecated) Time to back off during login to the thrift frontend service.
|
duration
|
1.0.0
kyuubi.frontend.bind.host|
<undefined>
|
(deprecated) Hostname or IP of the machine on which to run the thrift frontend service via binary protocol.
|
string
|
1.0.0
kyuubi.frontend.bind.port|
10009
|
(deprecated) Port of the machine on which to run the thrift frontend service via binary protocol.
|
int
|
1.0.0
kyuubi.frontend.connection.url.use.hostname|
false
|
When true, frontend services prefer hostname, otherwise, ip address
|
boolean
|
1.5.0
-kyuubi.frontend.login.timeout|
PT20S
|
(deprecated) Timeout for Thrift clients during login to the thrift frontend service.
|
duration
|
1.0.0
kyuubi.frontend.max.message.size|
104857600
|
(deprecated) Maximum message size in bytes a Kyuubi server will accept.
|
int
|
1.0.0
kyuubi.frontend.max.worker.threads|
999
|
(deprecated) Maximum number of threads in the of frontend worker thread pool for the thrift frontend service
|
int
|
1.0.0
kyuubi.frontend.min.worker.threads|
9
|
(deprecated) Minimum number of threads in the of frontend worker thread pool for the thrift frontend service
|
int
|
1.0.0
@@ -228,10 +226,8 @@ Key | Default | Meaning | Type | Since kyuubi.frontend.protocols|
THRIFT_BINARY
|
A comma separated list for all frontend protocols
|
seq
|
1.4.0
kyuubi.frontend.rest.bind.host|
<undefined>
|
Hostname or IP of the machine on which to run the REST frontend service.
|
string
|
1.4.0
kyuubi.frontend.rest.bind.port|
10099
|
Port of the machine on which to run the REST frontend service.
|
int
|
1.4.0
-kyuubi.frontend.thrift.backoff.slot.length|
PT0.1S
|
Time to back off during login to the thrift frontend service.
|
duration
|
1.4.0
kyuubi.frontend.thrift.binary.bind.host|
<undefined>
|
Hostname or IP of the machine on which to run the thrift frontend service via binary protocol.
|
string
|
1.4.0
kyuubi.frontend.thrift.binary.bind.port|
10009
|
Port of the machine on which to run the thrift frontend service via binary protocol.
|
int
|
1.4.0
-kyuubi.frontend.thrift.login.timeout|
PT20S
|
Timeout for Thrift clients during login to the thrift frontend service.
|
duration
|
1.4.0
kyuubi.frontend.thrift.max.message.size|
104857600
|
Maximum message size in bytes a Kyuubi server will accept.
|
int
|
1.4.0
kyuubi.frontend.thrift.max.worker.threads|
999
|
Maximum number of threads in the of frontend worker thread pool for the thrift frontend service
|
int
|
1.4.0
kyuubi.frontend.thrift.min.worker.threads|
9
|
Minimum number of threads in the of frontend worker thread pool for the thrift frontend service
|
int
|
1.4.0
diff --git a/externals/kyuubi-flink-sql-engine/pom.xml b/externals/kyuubi-flink-sql-engine/pom.xml index b9bc558c627..1bac8688d20 100644 --- a/externals/kyuubi-flink-sql-engine/pom.xml +++ b/externals/kyuubi-flink-sql-engine/pom.xml @@ -171,7 +171,8 @@ org.apache.curator:curator-framework org.apache.curator:curator-recipes\ org.apache.hive:hive-service-rpc - org.apache.thrift:* + org.apache.thrift:libfb303 + org.apache.thrift:libthrift org.apache.zookeeper:* diff --git a/externals/kyuubi-spark-sql-engine/pom.xml b/externals/kyuubi-spark-sql-engine/pom.xml index 4f5fd9442a6..ac75990ddb2 100644 --- a/externals/kyuubi-spark-sql-engine/pom.xml +++ b/externals/kyuubi-spark-sql-engine/pom.xml @@ -191,6 +191,9 @@ org.apache.curator:curator-client org.apache.curator:curator-framework org.apache.curator:curator-recipes + org.apache.hive:hive-service-rpc + org.apache.thrift:libfb303 + org.apache.thrift:libthrift @@ -201,6 +204,20 @@ org.apache.curator.** + + org.apache.thrift + ${kyuubi.shade.packageName}.org.apache.thrift + + org.apache.thrift.** + + + + org.apache.hive.service.rpc + ${kyuubi.shade.packageName}.org.apache.hive.service.rpc + + org.apache.hive.service.rpc.** + + diff --git a/externals/kyuubi-spark-sql-engine/src/test/java/org/apache/thrift/transport/TFramedTransport.java b/externals/kyuubi-spark-sql-engine/src/test/java/org/apache/thrift/transport/TFramedTransport.java new file mode 100644 index 00000000000..3777218efcf --- /dev/null +++ b/externals/kyuubi-spark-sql-engine/src/test/java/org/apache/thrift/transport/TFramedTransport.java @@ -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. + * + *

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)); + } +} diff --git a/kyuubi-common/pom.xml b/kyuubi-common/pom.xml index 816ccafb7d5..173f1a61a7b 100644 --- a/kyuubi-common/pom.xml +++ b/kyuubi-common/pom.xml @@ -94,6 +94,16 @@ guava + + org.apache.thrift + libfb303 + + + + org.apache.thrift + libthrift + + org.apache.hive hive-service-rpc diff --git a/kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala b/kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala index 1d4bf042d3b..999956ae2bc 100644 --- a/kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala +++ b/kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala @@ -364,34 +364,6 @@ object KyuubiConf { .version("1.4.0") .fallbackConf(FRONTEND_MAX_MESSAGE_SIZE) - @deprecated(s"using ${FRONTEND_THRIFT_LOGIN_TIMEOUT.key} instead", "1.4.0") - val FRONTEND_LOGIN_TIMEOUT: ConfigEntry[Long] = - buildConf("frontend.login.timeout") - .doc("(deprecated) Timeout for Thrift clients during login to the thrift frontend service.") - .version("1.0.0") - .timeConf - .createWithDefault(Duration.ofSeconds(20).toMillis) - - val FRONTEND_THRIFT_LOGIN_TIMEOUT: ConfigEntry[Long] = - buildConf("frontend.thrift.login.timeout") - .doc("Timeout for Thrift clients during login to the thrift frontend service.") - .version("1.4.0") - .fallbackConf(FRONTEND_LOGIN_TIMEOUT) - - @deprecated(s"using ${FRONTEND_THRIFT_LOGIN_BACKOFF_SLOT_LENGTH.key} instead", "1.4.0") - val FRONTEND_LOGIN_BACKOFF_SLOT_LENGTH: ConfigEntry[Long] = - buildConf("frontend.backoff.slot.length") - .doc("(deprecated) Time to back off during login to the thrift frontend service.") - .version("1.0.0") - .timeConf - .createWithDefault(Duration.ofMillis(100).toMillis) - - val FRONTEND_THRIFT_LOGIN_BACKOFF_SLOT_LENGTH: ConfigEntry[Long] = - buildConf("frontend.thrift.backoff.slot.length") - .doc("Time to back off during login to the thrift frontend service.") - .version("1.4.0") - .fallbackConf(FRONTEND_LOGIN_BACKOFF_SLOT_LENGTH) - val AUTHENTICATION_METHOD: ConfigEntry[Seq[String]] = buildConf("authentication") .doc("A comma separated list of client authentication types.