EdColeman commented on a change in pull request #2224: URL: https://github.com/apache/accumulo/pull/2224#discussion_r683802264
########## File path: server/base/src/main/java/org/apache/accumulo/server/conf/codec/GzipPropEncoding.java ########## @@ -0,0 +1,237 @@ +/* + * 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.accumulo.server.conf.codec; + +import static org.apache.accumulo.server.conf.codec.VersionedProperties.tsFormatter; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.UncheckedIOException; +import java.time.Instant; +import java.util.AbstractMap; +import java.util.HashMap; +import java.util.Map; +import java.util.zip.GZIPInputStream; +import java.util.zip.GZIPOutputStream; + +/** + * Initial property encoding that (optionally) uses gzip to compress the property map. The encoding + * version supported is EncodingVersion.V1_0. + */ +public class GzipPropEncoding implements PropSerdes { + + private final EncodingOptions encodingOpts; + + public GzipPropEncoding(final EncodingOptions encodingOpts) { + this.encodingOpts = encodingOpts; + } + + /** + * Serialize the versioned properties. The version information on the properties is updated if the + * data is successfully serialized. + * + * @param vProps + * the versioned properties. + * @return a byte array with the serialized properties. + */ + @Override + public byte[] toBytes(final VersionedProperties vProps) { + + try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(bos)) { + + // write header - version id, isCompressed + encodingOpts.encode(dos); + + // write updated property versioning info (data version, time stamp) + dos.writeInt(vProps.getNextVersion()); + dos.writeUTF(vProps.getTimestampISO()); Review comment: The timestamp seemed attractive when looking at the data - it provides a hint when the data was initially serialized. I also had thought about ways that having a timestamp could be used for deconfliction of concurrent updates - you would then know the order that the operations were serialized - but never took it further thinking something might be possible. The versioned properties should have a timestamp - but that could be time derived from the zNode modification time if we don't want to serialize it. I can drop the serialization, but it did seem like it was handy having that info available without needing extra info from zookeeper. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
