You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by "Duo Zhang (Jira)" <ji...@apache.org> on 2023/09/19 07:24:00 UTC
[jira] [Commented] (HBASE-22138) [hbase-thirdparty] Undo our direct dependence on protos in google.protobuf.Any in Procedure.proto
[ https://issues.apache.org/jira/browse/HBASE-22138?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17766669#comment-17766669 ]
Duo Zhang commented on HBASE-22138:
-----------------------------------
I tried locally and it seems that we can eliminate the dependency on any.proto without breaking the compatibility.
I used the below code to generate the serialized bytes for a Procedure which contains a state message.
{code}
Procedure p = Procedure.newBuilder().setClassName("class").setProcId(1)
.setSubmittedTime(System.currentTimeMillis()).setState(ProcedureState.RUNNABLE)
.setLastUpdate(System.currentTimeMillis())
.addStateMessage(
Any.newBuilder().setTypeUrl("url").setValue(ByteString.copyFromUtf8("value")).build())
.build();
Files.write(new File("/home/zhangduo/hbase/procedure.pb").toPath(), p.toByteArray());
{code}
Notice that, currently the Any is org.apache.hbase.thirdparty.com.google.protobuf.Any.
And then I just copied the Any message to Procedure.proto, with some modification as it is in proto3 syntax where 'required' or 'optional' is not required.
Now the Procedure.proto looks like
{code}
/**
* Just copied from protobuf to make sure we do not rely on unrelocated protobuf messages
*/
message Any {
// A URL/resource name that uniquely identifies the type of the serialized
// protocol buffer message. This string must contain at least
// one "/" character. The last segment of the URL's path must represent
// the fully qualified name of the type (as in
// `path/google.protobuf.Duration`). The name should be in a canonical form
// (e.g., leading "." is not accepted).
//
// In practice, teams usually precompile into the binary all types that they
// expect it to use in the context of Any. However, for URLs which use the
// scheme `http`, `https`, or no scheme, one can optionally set up a type
// server that maps type URLs to message definitions as follows:
//
// * If no scheme is provided, `https` is assumed.
// * An HTTP GET on the URL must yield a [google.protobuf.Type][]
// value in binary format, or produce an error.
// * Applications are allowed to cache lookup results based on the
// URL, or have them precompiled into a binary to avoid any
// lookup. Therefore, binary compatibility needs to be preserved
// on changes to types. (Use versioned type names to manage
// breaking changes.)
//
// Note: this functionality is not currently available in the official
// protobuf release, and it is not used for type URLs beginning with
// type.googleapis.com.
//
// Schemes other than `http`, `https` (or the empty scheme) might be
// used with implementation specific semantics.
//
optional string type_url = 1;
// Must be a valid serialized protocol buffer of the above specified type.
optional bytes value = 2;
}
/**
* Procedure metadata, serialized by the ProcedureStore to be able to recover the old state.
*/
message Procedure {
// internal "static" state
required string class_name = 1; // full classname to be able to instantiate the procedure
optional uint64 parent_id = 2; // parent if not a root-procedure otherwise not set
required uint64 proc_id = 3;
required uint64 submitted_time = 4;
optional string owner = 5;
// internal "runtime" state
required ProcedureState state = 6;
repeated uint32 stack_id = 7; // stack indices in case the procedure was running
required uint64 last_update = 8;
optional uint32 timeout = 9;
// user state/results
optional ForeignExceptionMessage exception = 10;
optional bytes result = 11; // opaque (user) result structure
optional bytes state_data = 12; // opaque (user) procedure internal-state - OBSOLATE
repeated Any state_message = 15; // opaque (user) procedure internal-state
// Nonce to prevent same procedure submit by multiple times
optional uint64 nonce_group = 13 [default = 0];
optional uint64 nonce = 14 [default = 0];
// whether the procedure has held the lock
optional bool locked = 16 [default = false];
// whether the procedure need to be bypassed
optional bool bypass = 17 [default = false];
}
{code}
Notice that, the 'repeated google.protobuf.Any state_message = 15;' has been changed to 'repeated Any state_message = 15;'.
And I use the below code to parse the generate bytes back to a Procedure instance.
{code}
byte[] bytes = Files.readAllBytes(new File("/home/zhangduo/hbase/procedure.pb").toPath());
Procedure p = Procedure.parseFrom(bytes);
System.out.println(p);
{code}
Notice that the Any is org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos.Any now.
And the code executed successfully. The output is
{noformat}
class_name: "class"
proc_id: 1
submitted_time: 1695106959050
state: RUNNABLE
last_update: 1695106959051
state_message {
type_url: "url"
value: "value"
}
{noformat}
It seems that the serialized pb message does not contains the naming string of a field type, so changing the field name does not break anything.
> [hbase-thirdparty] Undo our direct dependence on protos in google.protobuf.Any in Procedure.proto
> -------------------------------------------------------------------------------------------------
>
> Key: HBASE-22138
> URL: https://issues.apache.org/jira/browse/HBASE-22138
> Project: HBase
> Issue Type: Sub-task
> Components: thirdparty
> Reporter: Michael Stack
> Priority: Major
> Attachments: procedure.pb
>
>
> in our shaded jar, we've bundled a few unshaded google protos. We make use of these protos in some of our core classes. What is needed is a bit of careful work undoing our dependence on these types being careful to unsure we don't break compatibility (it should be fine but needs some careful operation).
> I've targeted this at the next version of hbase-thirdparty.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)