forked from opensearch-project/OpenSearch
-
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.
Compress and cache cluster state during validate join request (opense…
…arch-project#7321) * Compress and cache cluster state during validate join request Signed-off-by: Aman Khare <[email protected]> * Add changelog and license Signed-off-by: Aman Khare <[email protected]> * Add javadoc and correct styling Signed-off-by: Aman Khare <[email protected]> * Add new handler for sending compressed cluster state in validate join flow and refactor code Signed-off-by: Aman Khare <[email protected]> * Refactor util method Signed-off-by: Aman Khare <[email protected]> * optimize imports Signed-off-by: Aman Khare <[email protected]> * Use cluster state version based cache instead of time based cache Signed-off-by: Aman Khare <[email protected]> * style fix Signed-off-by: Aman Khare <[email protected]> * fix styling 2 Signed-off-by: Aman Khare <[email protected]> * Use concurrent hashmap instead of cache, add UT class for ClusterStateUtils Signed-off-by: Aman Khare <[email protected]> * style fix Signed-off-by: Aman Khare <[email protected]> * Use AtomicReference instead of ConcurrentHashMap Signed-off-by: Aman Khare <[email protected]> * Use method overloading to simplify the caller code Signed-off-by: Aman Khare <[email protected]> * Resolve conflicts Signed-off-by: Aman Khare <[email protected]> * Change code structure to separate the flow for JoinHelper and PublicationTransportHelper Signed-off-by: Aman Khare <[email protected]> * Remove unnecessary input.setVersion line Co-authored-by: Andrew Ross <[email protected]> Signed-off-by: Aman Khare <[email protected]> --------- Signed-off-by: Aman Khare <[email protected]> Signed-off-by: Aman Khare <[email protected]> Co-authored-by: Aman Khare <[email protected]> Co-authored-by: Andrew Ross <[email protected]>
- Loading branch information
1 parent
9cf4d71
commit 4663e11
Showing
9 changed files
with
485 additions
and
101 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
61 changes: 61 additions & 0 deletions
61
server/src/main/java/org/opensearch/cluster/coordination/CompressedStreamUtils.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,61 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.cluster.coordination; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.opensearch.Version; | ||
import org.opensearch.common.CheckedConsumer; | ||
import org.opensearch.common.bytes.BytesReference; | ||
import org.opensearch.common.compress.Compressor; | ||
import org.opensearch.common.compress.CompressorFactory; | ||
import org.opensearch.common.io.stream.BytesStreamOutput; | ||
import org.opensearch.common.io.stream.InputStreamStreamInput; | ||
import org.opensearch.common.io.stream.NamedWriteableAwareStreamInput; | ||
import org.opensearch.common.io.stream.NamedWriteableRegistry; | ||
import org.opensearch.common.io.stream.OutputStreamStreamOutput; | ||
import org.opensearch.common.io.stream.StreamInput; | ||
import org.opensearch.common.io.stream.StreamOutput; | ||
import org.opensearch.transport.BytesTransportRequest; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* A helper class to utilize the compressed stream. | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public final class CompressedStreamUtils { | ||
private static final Logger logger = LogManager.getLogger(CompressedStreamUtils.class); | ||
|
||
public static BytesReference createCompressedStream(Version version, CheckedConsumer<StreamOutput, IOException> outputConsumer) | ||
throws IOException { | ||
final BytesStreamOutput bStream = new BytesStreamOutput(); | ||
try (StreamOutput stream = new OutputStreamStreamOutput(CompressorFactory.COMPRESSOR.threadLocalOutputStream(bStream))) { | ||
stream.setVersion(version); | ||
outputConsumer.accept(stream); | ||
} | ||
final BytesReference serializedByteRef = bStream.bytes(); | ||
logger.trace("serialized writable object for node version [{}] with size [{}]", version, serializedByteRef.length()); | ||
return serializedByteRef; | ||
} | ||
|
||
public static StreamInput decompressBytes(BytesTransportRequest request, NamedWriteableRegistry namedWriteableRegistry) | ||
throws IOException { | ||
final Compressor compressor = CompressorFactory.compressor(request.bytes()); | ||
final StreamInput in; | ||
if (compressor != null) { | ||
in = new InputStreamStreamInput(compressor.threadLocalInputStream(request.bytes().streamInput())); | ||
} else { | ||
in = request.bytes().streamInput(); | ||
} | ||
in.setVersion(request.version()); | ||
return new NamedWriteableAwareStreamInput(in, namedWriteableRegistry); | ||
} | ||
} |
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
Oops, something went wrong.