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.
Adds Serializer interface for use in ehcache disk tier and elsewhere;…
… modifies existing disk tier impl to use it in a generic way Signed-off-by: Peter Alfonsi <[email protected]> Fixed byte[] key implementation to use ByteBuffer wrapper passed directly to ehcache Signed-off-by: Peter Alfonsi <[email protected]> Added tests for BytesReference serializer, and ehcache disk tier using BytesReference as a value
- Loading branch information
Peter Alfonsi
committed
Nov 2, 2023
1 parent
27cc265
commit e39514b
Showing
5 changed files
with
309 additions
and
24 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
server/src/main/java/org/opensearch/common/cache/tier/BytesReferenceSerializer.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,35 @@ | ||
/* | ||
* 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.common.cache.tier; | ||
|
||
import org.opensearch.core.common.bytes.BytesArray; | ||
import org.opensearch.core.common.bytes.BytesReference; | ||
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
|
||
public class BytesReferenceSerializer implements Serializer<BytesReference, byte[]> { | ||
// This class does not get passed to ehcache itself, so it's not required that classes match after deserialization. | ||
|
||
public BytesReferenceSerializer() {} | ||
@Override | ||
public byte[] serialize(BytesReference object) { | ||
return BytesReference.toBytes(object); | ||
} | ||
|
||
@Override | ||
public BytesReference deserialize(byte[] bytes) { | ||
return new BytesArray(bytes); | ||
} | ||
|
||
@Override | ||
public boolean equals(BytesReference object, byte[] bytes) { | ||
return Arrays.equals(serialize(object), bytes); | ||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
server/src/main/java/org/opensearch/common/cache/tier/Serializer.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,39 @@ | ||
/* | ||
* 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.common.cache.tier; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* An interface for serializers, to be used in disk caching tier and elsewhere. | ||
* T is the class of the original object, and U is the serialized class. | ||
*/ | ||
public interface Serializer<T, U> { | ||
/** | ||
* Serializes an object. | ||
* @param object A non-serialized object. | ||
* @return The serialized representation of the object. | ||
*/ | ||
U serialize(T object); | ||
|
||
/** | ||
* Deserializes bytes into an object. | ||
* @param bytes The serialized representation. | ||
* @return The original object. | ||
*/ | ||
T deserialize(U bytes); | ||
|
||
/** | ||
* Compares an object to a serialized representation of an object. | ||
* @param object A non-serialized objet | ||
* @param bytes Serialized representation of an object | ||
* @return true if representing the same object, false if not | ||
*/ | ||
boolean equals(T object, U bytes); | ||
} |
Oops, something went wrong.