Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 50 additions & 4 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
</dependency>

<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>${protobuf-java.version}</version>
<groupId>org.apache.phoenix.thirdparty</groupId>
<artifactId>phoenix-shaded-protobuf</artifactId>
<version>${phoenix.thirdparty.version}</version>
<scope>compile</scope>
</dependency>

Expand Down Expand Up @@ -174,11 +174,57 @@
<goal>compile</goal>
</goals>
<configuration>
<protocArtifact>${protobuf.group}:protoc:${protoc.version}:exe:${os.detected.classifier}</protocArtifact>
<protocArtifact>com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}</protocArtifact>
</configuration>
</execution>
</executions>
</plugin>
<!--
Need this old plugin to replace in generated files instances
of com.google.protobuf so instead its o.a.p.t.com.google.protobuf.
Plugin is old and in google code archive. Here is usage done by
anohther: https://github.com/beiliubei/maven-replacer-plugin/wiki/Usage-Guide
The mess with the regex in the below is to prevent replacement every time
we run mvn install. There is probably a better way of avoiding the
double interpolation but this is it for now.
-->
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<configuration>
<basedir>${basedir}/target/generated-sources/</basedir>
<includes>
<include>**/*.java</include>
</includes>
<!-- Ignore errors when missing files, because it means this build
was run with -Dprotoc.skip and there is no -Dreplacer.skip -->
<ignoreErrors>true</ignoreErrors>
<replacements>
<replacement>
<token>([^\.])com.google.protobuf</token>
<value>$1org.apache.phoenix.thirdparty.com.google.protobuf</value>
</replacement>
<replacement>
<token>(public)(\W+static)?(\W+final)?(\W+class)</token>
<value>@javax.annotation.Generated("proto") $1$2$3$4</value>
</replacement>
<!-- replacer doesn't support anchoring or negative lookbehind -->
<replacement>
<token>(@javax.annotation.Generated\("proto"\) ){2}</token>
<value>$1</value>
</replacement>
</replacements>
</configuration>
<executions>
<execution>
<goals>
<goal>replace</goal>
</goals>
<phase>process-sources</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
Expand Down
138 changes: 138 additions & 0 deletions common/src/main/java/org/apache/omid/protobuf/OmidProtobufDecoder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* 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.omid.protobuf;

import org.apache.phoenix.thirdparty.com.google.protobuf.ExtensionRegistry;
import org.apache.phoenix.thirdparty.com.google.protobuf.ExtensionRegistryLite;
import org.apache.phoenix.thirdparty.com.google.protobuf.Message;
import org.apache.phoenix.thirdparty.com.google.protobuf.MessageLite;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.codec.LengthFieldPrepender;
import io.netty.handler.codec.MessageToMessageDecoder;
import io.netty.util.internal.ObjectUtil;

import java.util.List;

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a note explaining where this was copied from and why

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comment

* This class is from netty-codec, but the imports for protobuf are changed to use phoenix-thirdparty
* so netty would not use other protobuf that might be present on the classpath.
*
* Decodes a received {@link ByteBuf} into a
* <a href="https://github.com/google/protobuf">Google Protocol Buffers</a>
* {@link Message} and {@link MessageLite}. Please note that this decoder must
* be used with a proper {@link ByteToMessageDecoder} such as {@link OmidProtobufVarint32FrameDecoder}
* or {@link LengthFieldBasedFrameDecoder} if you are using a stream-based
* transport such as TCP/IP. A typical setup for TCP/IP would be:
* <pre>
* {@link ChannelPipeline} pipeline = ...;
*
* // Decoders
* pipeline.addLast("frameDecoder",
* new {@link LengthFieldBasedFrameDecoder}(1048576, 0, 4, 0, 4));
* pipeline.addLast("protobufDecoder",
* new {@link OmidProtobufDecoder}(MyMessage.getDefaultInstance()));
*
* // Encoder
* pipeline.addLast("frameEncoder", new {@link LengthFieldPrepender}(4));
* pipeline.addLast("protobufEncoder", new {@link OmidProtobufEncoder}());
* </pre>
* and then you can use a {@code MyMessage} instead of a {@link ByteBuf}
* as a message:
* <pre>
* void channelRead({@link ChannelHandlerContext} ctx, Object msg) {
* MyMessage req = (MyMessage) msg;
* MyMessage res = MyMessage.newBuilder().setText(
* "Did you say '" + req.getText() + "'?").build();
* ch.write(res);
* }
* </pre>
*/
@Sharable
public class OmidProtobufDecoder extends MessageToMessageDecoder<ByteBuf> {

private static final boolean HAS_PARSER;

static {
boolean hasParser = false;
try {
// MessageLite.getParserForType() is not available until protobuf 2.5.0.
MessageLite.class.getDeclaredMethod("getParserForType");
hasParser = true;
} catch (Throwable t) {
// Ignore
}

HAS_PARSER = hasParser;
}

private final MessageLite prototype;
private final ExtensionRegistryLite extensionRegistry;

/**
* Creates a new instance.
*/
public OmidProtobufDecoder(MessageLite prototype) {
this(prototype, null);
}

public OmidProtobufDecoder(MessageLite prototype, ExtensionRegistry extensionRegistry) {
this(prototype, (ExtensionRegistryLite) extensionRegistry);
}

public OmidProtobufDecoder(MessageLite prototype, ExtensionRegistryLite extensionRegistry) {
this.prototype = ObjectUtil.checkNotNull(prototype, "prototype").getDefaultInstanceForType();
this.extensionRegistry = extensionRegistry;
}

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out)
throws Exception {
final byte[] array;
final int offset;
final int length = msg.readableBytes();
if (msg.hasArray()) {
array = msg.array();
offset = msg.arrayOffset() + msg.readerIndex();
} else {
array = ByteBufUtil.getBytes(msg, msg.readerIndex(), length, false);
offset = 0;
}

if (extensionRegistry == null) {
if (HAS_PARSER) {
out.add(prototype.getParserForType().parseFrom(array, offset, length));
} else {
out.add(prototype.newBuilderForType().mergeFrom(array, offset, length).build());
}
} else {
if (HAS_PARSER) {
out.add(prototype.getParserForType().parseFrom(
array, offset, length, extensionRegistry));
} else {
out.add(prototype.newBuilderForType().mergeFrom(
array, offset, length, extensionRegistry).build());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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.omid.protobuf;

import org.apache.phoenix.thirdparty.com.google.protobuf.Message;
import org.apache.phoenix.thirdparty.com.google.protobuf.MessageLite;
import org.apache.phoenix.thirdparty.com.google.protobuf.MessageLiteOrBuilder;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.codec.LengthFieldPrepender;
import io.netty.handler.codec.MessageToMessageEncoder;

import java.util.List;

import static io.netty.buffer.Unpooled.wrappedBuffer;

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a note explaining where this was copied from and why

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comment

* This class is from netty-codec, but the imports for protobuf are changed to use phoenix-thirdparty
* so netty would not use other protobuf that might be present on the classpath.
*
* Encodes the requested <a href="https://github.com/google/protobuf">Google
* Protocol Buffers</a> {@link Message} and {@link MessageLite} into a
* {@link ByteBuf}. A typical setup for TCP/IP would be:
* <pre>
* {@link ChannelPipeline} pipeline = ...;
*
* // Decoders
* pipeline.addLast("frameDecoder",
* new {@link LengthFieldBasedFrameDecoder}(1048576, 0, 4, 0, 4));
* pipeline.addLast("protobufDecoder",
* new {@link OmidProtobufDecoder}(MyMessage.getDefaultInstance()));
*
* // Encoder
* pipeline.addLast("frameEncoder", new {@link LengthFieldPrepender}(4));
* pipeline.addLast("protobufEncoder", new {@link OmidProtobufEncoder}());
* </pre>
* and then you can use a {@code MyMessage} instead of a {@link ByteBuf}
* as a message:
* <pre>
* void channelRead({@link ChannelHandlerContext} ctx, Object msg) {
* MyMessage req = (MyMessage) msg;
* MyMessage res = MyMessage.newBuilder().setText(
* "Did you say '" + req.getText() + "'?").build();
* ch.write(res);
* }
* </pre>
*/
@Sharable
public class OmidProtobufEncoder extends MessageToMessageEncoder<MessageLiteOrBuilder> {
@Override
protected void encode(ChannelHandlerContext ctx, MessageLiteOrBuilder msg, List<Object> out)
throws Exception {
if (msg instanceof MessageLite) {
out.add(wrappedBuffer(((MessageLite) msg).toByteArray()));
return;
}
if (msg instanceof MessageLite.Builder) {
out.add(wrappedBuffer(((MessageLite.Builder) msg).build().toByteArray()));
}
}
}
5 changes: 3 additions & 2 deletions common/src/main/proto/TSOProto.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// limitations under the License.
//

syntax = "proto3";
option java_package = "org.apache.omid.proto";

option optimize_for = SPEED;
Expand All @@ -32,7 +33,7 @@ message TimestampRequest {

message CommitRequest {
optional int64 startTimestamp = 1;
optional bool isRetry = 2 [default = false];
optional bool isRetry = 2;
repeated int64 cellId = 3;
repeated int64 TableId = 4;
}
Expand Down Expand Up @@ -75,7 +76,7 @@ message HandshakeRequest {
message HandshakeResponse {
optional bool clientCompatible = 1;
optional Capabilities serverCapabilities = 2;
optional bool lowLatency = 3[default= false];
optional bool lowLatency = 3;
}

message Transaction {
Expand Down
6 changes: 6 additions & 0 deletions hbase-commit-table/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@

<!-- end distributed comm -->

<dependency>
<groupId>org.apache.phoenix.thirdparty</groupId>
<artifactId>phoenix-shaded-protobuf</artifactId>
<version>${phoenix.thirdparty.version}</version>
</dependency>

<!-- utils -->

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
import org.apache.phoenix.thirdparty.com.google.common.util.concurrent.AbstractFuture;
import org.apache.phoenix.thirdparty.com.google.common.util.concurrent.ListenableFuture;
import org.apache.phoenix.thirdparty.com.google.common.util.concurrent.SettableFuture;
import com.google.protobuf.CodedInputStream;
import com.google.protobuf.CodedOutputStream;
import org.apache.phoenix.thirdparty.com.google.protobuf.CodedInputStream;
import org.apache.phoenix.thirdparty.com.google.protobuf.CodedOutputStream;

public class HBaseCommitTable implements CommitTable {

Expand Down
5 changes: 5 additions & 0 deletions hbase-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
<artifactId>commons-lang3</artifactId>
</dependency>

<dependency>
<groupId>org.apache.phoenix.thirdparty</groupId>
<artifactId>phoenix-shaded-protobuf</artifactId>
<version>${phoenix.thirdparty.version}</version>
</dependency>
<dependency>
<groupId>org.apache.phoenix.thirdparty</groupId>
<artifactId>phoenix-shaded-guava</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/
package org.apache.omid.committable.hbase;

import com.google.protobuf.CodedInputStream;
import com.google.protobuf.CodedOutputStream;
import org.apache.phoenix.thirdparty.com.google.protobuf.CodedInputStream;
import org.apache.phoenix.thirdparty.com.google.protobuf.CodedOutputStream;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package org.apache.omid.transaction;

import com.google.protobuf.InvalidProtocolBufferException;
import org.apache.phoenix.thirdparty.com.google.protobuf.InvalidProtocolBufferException;

import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.Scan;
Expand Down
Loading