Skip to content

Commit a51fe58

Browse files
committed
[KYUUBI-SHADED #29] [KYUUBI-SHADED #28] Step 2/2: Overwrite SnapStream to remove deps of snappy in ZK client 3.6
### _Why are the changes needed?_ This is step 2 of #28 > 2. remove the Snappy support (simply throw `UnsupportedOperationException`) in `org.apache.zookeeper.server.persistence.SnapStream` and snappy deps ### _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 - [ ] [Run test](https://kyuubi.readthedocs.io/en/master/develop_tools/testing.html#running-tests) locally before make a pull request - [x] Verified through apache/kyuubi#5783 Closes #29 from pan3793/snappy-2. a109d1c [Cheng Pan] [KYUUBI-SHADED #28] Step 1/2: Overwrite SnapStream to remove deps of snappy in ZK client 3.6 Authored-by: Cheng Pan <chengpan@apache.org> Signed-off-by: Cheng Pan <chengpan@apache.org>
1 parent 06eb6e7 commit a51fe58

File tree

4 files changed

+8
-36
lines changed

4 files changed

+8
-36
lines changed

kyuubi-relocated-zookeeper-parent/kyuubi-relocated-zookeeper-36/pom.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ under the License.
3636
<zookeeper.version>3.6.4</zookeeper.version>
3737
<curator.version>5.4.0</curator.version>
3838
<netty.version>4.1.91.Final</netty.version>
39-
<snappy.version>1.1.8.4</snappy.version>
4039
</properties>
4140

4241
<dependencyManagement>
@@ -161,11 +160,5 @@ under the License.
161160
</exclusion>
162161
</exclusions>
163162
</dependency>
164-
<dependency>
165-
<!-- required by kyuubi embedded Zookeeper server to bootstrap -->
166-
<groupId>org.xerial.snappy</groupId>
167-
<artifactId>snappy-java</artifactId>
168-
<version>${snappy.version}</version>
169-
</dependency>
170163
</dependencies>
171164
</project>

kyuubi-relocated-zookeeper-parent/kyuubi-relocated-zookeeper-36/src/main/java/org/apache/zookeeper/server/persistence/SnapStream.java

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.io.OutputStream;
3030
import java.io.RandomAccessFile;
3131
import java.nio.ByteBuffer;
32-
import java.util.Arrays;
3332
import java.util.zip.Adler32;
3433
import java.util.zip.CheckedInputStream;
3534
import java.util.zip.CheckedOutputStream;
@@ -40,9 +39,6 @@
4039
import org.apache.zookeeper.common.AtomicFileOutputStream;
4140
import org.slf4j.Logger;
4241
import org.slf4j.LoggerFactory;
43-
import org.xerial.snappy.SnappyCodec;
44-
import org.xerial.snappy.SnappyInputStream;
45-
import org.xerial.snappy.SnappyOutputStream;
4642

4743
/** Represent the Stream used in serialize and deserialize the Snapshot. */
4844
public class SnapStream {
@@ -106,8 +102,8 @@ public static CheckedInputStream getInputStream(File file) throws IOException {
106102
is = new GZIPInputStream(fis);
107103
break;
108104
case SNAPPY:
109-
is = new SnappyInputStream(fis);
110-
break;
105+
throw new UnsupportedOperationException(
106+
"[KYUUBI-SHADED #28] " + ZOOKEEPER_SHAPSHOT_STREAM_MODE + " does not support snappy");
111107
case CHECKED:
112108
default:
113109
is = new BufferedInputStream(fis);
@@ -131,8 +127,8 @@ public static CheckedOutputStream getOutputStream(File file, boolean fsync) thro
131127
os = new GZIPOutputStream(fos);
132128
break;
133129
case SNAPPY:
134-
os = new SnappyOutputStream(fos);
135-
break;
130+
throw new UnsupportedOperationException(
131+
"[KYUUBI-SHADED #28] " + ZOOKEEPER_SHAPSHOT_STREAM_MODE + " does not support snappy");
136132
case CHECKED:
137133
default:
138134
os = new BufferedOutputStream(fos);
@@ -184,8 +180,8 @@ public static boolean isValidSnapshot(File file) throws IOException {
184180
isValid = isValidGZipStream(file);
185181
break;
186182
case SNAPPY:
187-
isValid = isValidSnappyStream(file);
188-
break;
183+
throw new UnsupportedOperationException(
184+
"[KYUUBI-SHADED #28] " + ZOOKEEPER_SHAPSHOT_STREAM_MODE + " does not support snappy");
189185
case CHECKED:
190186
default:
191187
isValid = isValidCheckedStream(file);
@@ -252,20 +248,8 @@ private static boolean isValidGZipStream(File f) throws IOException {
252248
* @throws IOException
253249
*/
254250
private static boolean isValidSnappyStream(File f) throws IOException {
255-
byte[] byteArray = new byte[SnappyCodec.MAGIC_LEN];
256-
try (FileInputStream fis = new FileInputStream(f)) {
257-
if (SnappyCodec.MAGIC_LEN != fis.read(byteArray, 0, SnappyCodec.MAGIC_LEN)) {
258-
LOG.error("Read incorrect number of bytes from {}", f.getName());
259-
return false;
260-
}
261-
ByteBuffer bb = ByteBuffer.wrap(byteArray);
262-
byte[] magicHeader = new byte[SnappyCodec.MAGIC_LEN];
263-
bb.get(magicHeader, 0, SnappyCodec.MAGIC_LEN);
264-
return Arrays.equals(magicHeader, SnappyCodec.getMagicHeader());
265-
} catch (FileNotFoundException e) {
266-
LOG.error("Unable to open file {}", f.getName(), e);
267-
return false;
268-
}
251+
throw new UnsupportedOperationException(
252+
"[KYUUBI-SHADED #28] " + ZOOKEEPER_SHAPSHOT_STREAM_MODE + " does not support snappy");
269253
}
270254

271255
/**

kyuubi-relocated-zookeeper-parent/kyuubi-relocated-zookeeper-36/src/main/resources/META-INF/NOTICE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@ This project bundles the following dependencies under the Apache Software Licens
1313
- org.apache.curator:curator-recipes:5.4.0
1414
- org.apache.zookeeper:zookeeper-jute:3.6.4
1515
- org.apache.zookeeper:zookeeper:3.6.4
16-
- org.xerial.snappy:xerial-java:1.1.8.4

kyuubi-relocated-zookeeper-parent/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,6 @@ under the License.
9797
<pattern>com.google</pattern>
9898
<shadedPattern>${shading.prefix}.google</shadedPattern>
9999
</relocation>
100-
<relocation>
101-
<pattern>org.xerial.snappy</pattern>
102-
<shadedPattern>${shading.prefix}.snappy</shadedPattern>
103-
</relocation>
104100
</relocations>
105101
</configuration>
106102
</execution>

0 commit comments

Comments
 (0)