forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate zstd with security manager
- Loading branch information
Showing
4 changed files
with
93 additions
and
44 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
48 changes: 48 additions & 0 deletions
48
server/src/main/java/org/elasticsearch/index/codec/postings/Zstd.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,48 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.index.codec.postings; | ||
|
||
import org.apache.lucene.util.BytesRefBuilder; | ||
|
||
import java.security.AccessController; | ||
import java.security.PrivilegedAction; | ||
|
||
public final class Zstd { | ||
|
||
public static void compress(BytesRefBuilder raw, BytesRefBuilder out, int compressionLevel) { | ||
AccessController.doPrivileged(new PrivilegedAction<Void>() { | ||
@Override | ||
public Void run() { | ||
int estimatedBytes = Math.toIntExact(com.github.luben.zstd.Zstd.compressBound(raw.length())); | ||
out.grow(estimatedBytes); | ||
long len = com.github.luben.zstd.Zstd.compressByteArray( | ||
out.bytes(), | ||
0, | ||
estimatedBytes, | ||
raw.bytes(), | ||
0, | ||
raw.length(), | ||
compressionLevel | ||
); | ||
out.setLength(Math.toIntExact(len)); | ||
return null; | ||
} | ||
}); | ||
} | ||
|
||
public static void decompress(byte[] dst, int dstSize, byte[] src, int srcSize) { | ||
AccessController.doPrivileged(new PrivilegedAction<Void>() { | ||
@Override | ||
public Void run() { | ||
com.github.luben.zstd.Zstd.decompressByteArray(dst, 0, dstSize, src, 0, srcSize); | ||
return null; | ||
} | ||
}); | ||
} | ||
} |
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