From fe4bfa2a671549a402e165247901e30a0ddb72f5 Mon Sep 17 00:00:00 2001 From: cauchy1988 Date: Thu, 3 Mar 2022 14:13:47 +0800 Subject: [PATCH] feat: add a batch get client interface which uses 'BATCH_GET' rpc for read optimization (#175) --- idl/rrdb.thrift | 24 + .../infra/pegasus/apps/batch_get_request.java | 442 +++++++++ .../pegasus/apps/batch_get_response.java | 838 ++++++++++++++++ .../xiaomi/infra/pegasus/apps/full_data.java | 611 ++++++++++++ .../xiaomi/infra/pegasus/apps/full_key.java | 502 ++++++++++ .../com/xiaomi/infra/pegasus/apps/rrdb.java | 902 +++++++++++++++++- .../infra/pegasus/client/PegasusClient.java | 8 + .../client/PegasusClientInterface.java | 4 + .../infra/pegasus/client/PegasusTable.java | 136 +++ .../pegasus/client/PegasusTableInterface.java | 47 + .../pegasus/operator/batch_get_operator.java | 58 ++ .../client/TestBatchGetByPartitions.java | 122 +++ 12 files changed, 3690 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/xiaomi/infra/pegasus/apps/batch_get_request.java create mode 100644 src/main/java/com/xiaomi/infra/pegasus/apps/batch_get_response.java create mode 100644 src/main/java/com/xiaomi/infra/pegasus/apps/full_data.java create mode 100644 src/main/java/com/xiaomi/infra/pegasus/apps/full_key.java create mode 100644 src/main/java/com/xiaomi/infra/pegasus/operator/batch_get_operator.java create mode 100644 src/test/java/com/xiaomi/infra/pegasus/client/TestBatchGetByPartitions.java diff --git a/idl/rrdb.thrift b/idl/rrdb.thrift index 4ba91f5e56..c18051a814 100644 --- a/idl/rrdb.thrift +++ b/idl/rrdb.thrift @@ -147,6 +147,29 @@ struct multi_get_response 6:string server; } +struct batch_get_request { + 1:list keys; +} + +struct full_key { + 1:base.blob hash_key; + 2:base.blob sort_key; +} + +struct batch_get_response { + 1:i32 error; + 2:list data; + 3:i32 app_id; + 4:i32 partition_index; + 6:string server; +} + +struct full_data { + 1:base.blob hash_key; + 2:base.blob sort_key; + 3:base.blob value; +} + struct incr_request { 1:base.blob key; @@ -264,6 +287,7 @@ service rrdb check_and_mutate_response check_and_mutate(1:check_and_mutate_request request); read_response get(1:base.blob key); multi_get_response multi_get(1:multi_get_request request); + batch_get_response batch_get(1:batch_get_request request); count_response sortkey_count(1:base.blob hash_key); ttl_response ttl(1:base.blob key); scan_response get_scanner(1:get_scanner_request request); diff --git a/src/main/java/com/xiaomi/infra/pegasus/apps/batch_get_request.java b/src/main/java/com/xiaomi/infra/pegasus/apps/batch_get_request.java new file mode 100644 index 0000000000..c0c5c480e8 --- /dev/null +++ b/src/main/java/com/xiaomi/infra/pegasus/apps/batch_get_request.java @@ -0,0 +1,442 @@ +// 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. +/** + * Autogenerated by Thrift Compiler (0.11.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.xiaomi.infra.pegasus.apps; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.11.0)", date = "2022-02-12") +public class batch_get_request implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("batch_get_request"); + + private static final org.apache.thrift.protocol.TField KEYS_FIELD_DESC = new org.apache.thrift.protocol.TField("keys", org.apache.thrift.protocol.TType.LIST, (short)1); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new batch_get_requestStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new batch_get_requestTupleSchemeFactory(); + + public java.util.List keys; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + KEYS((short)1, "keys"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // KEYS + return KEYS; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.KEYS, new org.apache.thrift.meta_data.FieldMetaData("keys", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRUCT , "full_key")))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(batch_get_request.class, metaDataMap); + } + + public batch_get_request() { + } + + public batch_get_request( + java.util.List keys) + { + this(); + this.keys = keys; + } + + /** + * Performs a deep copy on other. + */ + public batch_get_request(batch_get_request other) { + if (other.isSetKeys()) { + java.util.List __this__keys = new java.util.ArrayList(other.keys.size()); + for (full_key other_element : other.keys) { + __this__keys.add(new full_key(other_element)); + } + this.keys = __this__keys; + } + } + + public batch_get_request deepCopy() { + return new batch_get_request(this); + } + + @Override + public void clear() { + this.keys = null; + } + + public int getKeysSize() { + return (this.keys == null) ? 0 : this.keys.size(); + } + + public java.util.Iterator getKeysIterator() { + return (this.keys == null) ? null : this.keys.iterator(); + } + + public void addToKeys(full_key elem) { + if (this.keys == null) { + this.keys = new java.util.ArrayList(); + } + this.keys.add(elem); + } + + public java.util.List getKeys() { + return this.keys; + } + + public batch_get_request setKeys(java.util.List keys) { + this.keys = keys; + return this; + } + + public void unsetKeys() { + this.keys = null; + } + + /** Returns true if field keys is set (has been assigned a value) and false otherwise */ + public boolean isSetKeys() { + return this.keys != null; + } + + public void setKeysIsSet(boolean value) { + if (!value) { + this.keys = null; + } + } + + public void setFieldValue(_Fields field, java.lang.Object value) { + switch (field) { + case KEYS: + if (value == null) { + unsetKeys(); + } else { + setKeys((java.util.List)value); + } + break; + + } + } + + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case KEYS: + return getKeys(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case KEYS: + return isSetKeys(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof batch_get_request) + return this.equals((batch_get_request)that); + return false; + } + + public boolean equals(batch_get_request that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_keys = true && this.isSetKeys(); + boolean that_present_keys = true && that.isSetKeys(); + if (this_present_keys || that_present_keys) { + if (!(this_present_keys && that_present_keys)) + return false; + if (!this.keys.equals(that.keys)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetKeys()) ? 131071 : 524287); + if (isSetKeys()) + hashCode = hashCode * 8191 + keys.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(batch_get_request other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetKeys()).compareTo(other.isSetKeys()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetKeys()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.keys, other.keys); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("batch_get_request("); + boolean first = true; + + sb.append("keys:"); + if (this.keys == null) { + sb.append("null"); + } else { + sb.append(this.keys); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class batch_get_requestStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public batch_get_requestStandardScheme getScheme() { + return new batch_get_requestStandardScheme(); + } + } + + private static class batch_get_requestStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, batch_get_request struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // KEYS + if (schemeField.type == org.apache.thrift.protocol.TType.LIST) { + { + org.apache.thrift.protocol.TList _list32 = iprot.readListBegin(); + struct.keys = new java.util.ArrayList(_list32.size); + full_key _elem33; + for (int _i34 = 0; _i34 < _list32.size; ++_i34) + { + _elem33 = new full_key(); + _elem33.read(iprot); + struct.keys.add(_elem33); + } + iprot.readListEnd(); + } + struct.setKeysIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, batch_get_request struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.keys != null) { + oprot.writeFieldBegin(KEYS_FIELD_DESC); + { + oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, struct.keys.size())); + for (full_key _iter35 : struct.keys) + { + _iter35.write(oprot); + } + oprot.writeListEnd(); + } + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class batch_get_requestTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public batch_get_requestTupleScheme getScheme() { + return new batch_get_requestTupleScheme(); + } + } + + private static class batch_get_requestTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, batch_get_request struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetKeys()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetKeys()) { + { + oprot.writeI32(struct.keys.size()); + for (full_key _iter36 : struct.keys) + { + _iter36.write(oprot); + } + } + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, batch_get_request struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + { + org.apache.thrift.protocol.TList _list37 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32()); + struct.keys = new java.util.ArrayList(_list37.size); + full_key _elem38; + for (int _i39 = 0; _i39 < _list37.size; ++_i39) + { + _elem38 = new full_key(); + _elem38.read(iprot); + struct.keys.add(_elem38); + } + } + struct.setKeysIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } +} + diff --git a/src/main/java/com/xiaomi/infra/pegasus/apps/batch_get_response.java b/src/main/java/com/xiaomi/infra/pegasus/apps/batch_get_response.java new file mode 100644 index 0000000000..05b9ee645b --- /dev/null +++ b/src/main/java/com/xiaomi/infra/pegasus/apps/batch_get_response.java @@ -0,0 +1,838 @@ +// 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. +/** + * Autogenerated by Thrift Compiler (0.11.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.xiaomi.infra.pegasus.apps; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.11.0)", date = "2022-02-12") +public class batch_get_response implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("batch_get_response"); + + private static final org.apache.thrift.protocol.TField ERROR_FIELD_DESC = new org.apache.thrift.protocol.TField("error", org.apache.thrift.protocol.TType.I32, (short)1); + private static final org.apache.thrift.protocol.TField DATA_FIELD_DESC = new org.apache.thrift.protocol.TField("data", org.apache.thrift.protocol.TType.LIST, (short)2); + private static final org.apache.thrift.protocol.TField APP_ID_FIELD_DESC = new org.apache.thrift.protocol.TField("app_id", org.apache.thrift.protocol.TType.I32, (short)3); + private static final org.apache.thrift.protocol.TField PARTITION_INDEX_FIELD_DESC = new org.apache.thrift.protocol.TField("partition_index", org.apache.thrift.protocol.TType.I32, (short)4); + private static final org.apache.thrift.protocol.TField SERVER_FIELD_DESC = new org.apache.thrift.protocol.TField("server", org.apache.thrift.protocol.TType.STRING, (short)6); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new batch_get_responseStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new batch_get_responseTupleSchemeFactory(); + + public int error; // required + public java.util.List data; // required + public int app_id; // required + public int partition_index; // required + public java.lang.String server; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + ERROR((short)1, "error"), + DATA((short)2, "data"), + APP_ID((short)3, "app_id"), + PARTITION_INDEX((short)4, "partition_index"), + SERVER((short)6, "server"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // ERROR + return ERROR; + case 2: // DATA + return DATA; + case 3: // APP_ID + return APP_ID; + case 4: // PARTITION_INDEX + return PARTITION_INDEX; + case 6: // SERVER + return SERVER; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private static final int __ERROR_ISSET_ID = 0; + private static final int __APP_ID_ISSET_ID = 1; + private static final int __PARTITION_INDEX_ISSET_ID = 2; + private byte __isset_bitfield = 0; + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.ERROR, new org.apache.thrift.meta_data.FieldMetaData("error", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32))); + tmpMap.put(_Fields.DATA, new org.apache.thrift.meta_data.FieldMetaData("data", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRUCT , "full_data")))); + tmpMap.put(_Fields.APP_ID, new org.apache.thrift.meta_data.FieldMetaData("app_id", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32))); + tmpMap.put(_Fields.PARTITION_INDEX, new org.apache.thrift.meta_data.FieldMetaData("partition_index", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32))); + tmpMap.put(_Fields.SERVER, new org.apache.thrift.meta_data.FieldMetaData("server", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(batch_get_response.class, metaDataMap); + } + + public batch_get_response() { + } + + public batch_get_response( + int error, + java.util.List data, + int app_id, + int partition_index, + java.lang.String server) + { + this(); + this.error = error; + setErrorIsSet(true); + this.data = data; + this.app_id = app_id; + setApp_idIsSet(true); + this.partition_index = partition_index; + setPartition_indexIsSet(true); + this.server = server; + } + + /** + * Performs a deep copy on other. + */ + public batch_get_response(batch_get_response other) { + __isset_bitfield = other.__isset_bitfield; + this.error = other.error; + if (other.isSetData()) { + java.util.List __this__data = new java.util.ArrayList(other.data.size()); + for (full_data other_element : other.data) { + __this__data.add(new full_data(other_element)); + } + this.data = __this__data; + } + this.app_id = other.app_id; + this.partition_index = other.partition_index; + if (other.isSetServer()) { + this.server = other.server; + } + } + + public batch_get_response deepCopy() { + return new batch_get_response(this); + } + + @Override + public void clear() { + setErrorIsSet(false); + this.error = 0; + this.data = null; + setApp_idIsSet(false); + this.app_id = 0; + setPartition_indexIsSet(false); + this.partition_index = 0; + this.server = null; + } + + public int getError() { + return this.error; + } + + public batch_get_response setError(int error) { + this.error = error; + setErrorIsSet(true); + return this; + } + + public void unsetError() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __ERROR_ISSET_ID); + } + + /** Returns true if field error is set (has been assigned a value) and false otherwise */ + public boolean isSetError() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __ERROR_ISSET_ID); + } + + public void setErrorIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __ERROR_ISSET_ID, value); + } + + public int getDataSize() { + return (this.data == null) ? 0 : this.data.size(); + } + + public java.util.Iterator getDataIterator() { + return (this.data == null) ? null : this.data.iterator(); + } + + public void addToData(full_data elem) { + if (this.data == null) { + this.data = new java.util.ArrayList(); + } + this.data.add(elem); + } + + public java.util.List getData() { + return this.data; + } + + public batch_get_response setData(java.util.List data) { + this.data = data; + return this; + } + + public void unsetData() { + this.data = null; + } + + /** Returns true if field data is set (has been assigned a value) and false otherwise */ + public boolean isSetData() { + return this.data != null; + } + + public void setDataIsSet(boolean value) { + if (!value) { + this.data = null; + } + } + + public int getApp_id() { + return this.app_id; + } + + public batch_get_response setApp_id(int app_id) { + this.app_id = app_id; + setApp_idIsSet(true); + return this; + } + + public void unsetApp_id() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __APP_ID_ISSET_ID); + } + + /** Returns true if field app_id is set (has been assigned a value) and false otherwise */ + public boolean isSetApp_id() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __APP_ID_ISSET_ID); + } + + public void setApp_idIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __APP_ID_ISSET_ID, value); + } + + public int getPartition_index() { + return this.partition_index; + } + + public batch_get_response setPartition_index(int partition_index) { + this.partition_index = partition_index; + setPartition_indexIsSet(true); + return this; + } + + public void unsetPartition_index() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __PARTITION_INDEX_ISSET_ID); + } + + /** Returns true if field partition_index is set (has been assigned a value) and false otherwise */ + public boolean isSetPartition_index() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __PARTITION_INDEX_ISSET_ID); + } + + public void setPartition_indexIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __PARTITION_INDEX_ISSET_ID, value); + } + + public java.lang.String getServer() { + return this.server; + } + + public batch_get_response setServer(java.lang.String server) { + this.server = server; + return this; + } + + public void unsetServer() { + this.server = null; + } + + /** Returns true if field server is set (has been assigned a value) and false otherwise */ + public boolean isSetServer() { + return this.server != null; + } + + public void setServerIsSet(boolean value) { + if (!value) { + this.server = null; + } + } + + public void setFieldValue(_Fields field, java.lang.Object value) { + switch (field) { + case ERROR: + if (value == null) { + unsetError(); + } else { + setError((java.lang.Integer)value); + } + break; + + case DATA: + if (value == null) { + unsetData(); + } else { + setData((java.util.List)value); + } + break; + + case APP_ID: + if (value == null) { + unsetApp_id(); + } else { + setApp_id((java.lang.Integer)value); + } + break; + + case PARTITION_INDEX: + if (value == null) { + unsetPartition_index(); + } else { + setPartition_index((java.lang.Integer)value); + } + break; + + case SERVER: + if (value == null) { + unsetServer(); + } else { + setServer((java.lang.String)value); + } + break; + + } + } + + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case ERROR: + return getError(); + + case DATA: + return getData(); + + case APP_ID: + return getApp_id(); + + case PARTITION_INDEX: + return getPartition_index(); + + case SERVER: + return getServer(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case ERROR: + return isSetError(); + case DATA: + return isSetData(); + case APP_ID: + return isSetApp_id(); + case PARTITION_INDEX: + return isSetPartition_index(); + case SERVER: + return isSetServer(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof batch_get_response) + return this.equals((batch_get_response)that); + return false; + } + + public boolean equals(batch_get_response that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_error = true; + boolean that_present_error = true; + if (this_present_error || that_present_error) { + if (!(this_present_error && that_present_error)) + return false; + if (this.error != that.error) + return false; + } + + boolean this_present_data = true && this.isSetData(); + boolean that_present_data = true && that.isSetData(); + if (this_present_data || that_present_data) { + if (!(this_present_data && that_present_data)) + return false; + if (!this.data.equals(that.data)) + return false; + } + + boolean this_present_app_id = true; + boolean that_present_app_id = true; + if (this_present_app_id || that_present_app_id) { + if (!(this_present_app_id && that_present_app_id)) + return false; + if (this.app_id != that.app_id) + return false; + } + + boolean this_present_partition_index = true; + boolean that_present_partition_index = true; + if (this_present_partition_index || that_present_partition_index) { + if (!(this_present_partition_index && that_present_partition_index)) + return false; + if (this.partition_index != that.partition_index) + return false; + } + + boolean this_present_server = true && this.isSetServer(); + boolean that_present_server = true && that.isSetServer(); + if (this_present_server || that_present_server) { + if (!(this_present_server && that_present_server)) + return false; + if (!this.server.equals(that.server)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + error; + + hashCode = hashCode * 8191 + ((isSetData()) ? 131071 : 524287); + if (isSetData()) + hashCode = hashCode * 8191 + data.hashCode(); + + hashCode = hashCode * 8191 + app_id; + + hashCode = hashCode * 8191 + partition_index; + + hashCode = hashCode * 8191 + ((isSetServer()) ? 131071 : 524287); + if (isSetServer()) + hashCode = hashCode * 8191 + server.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(batch_get_response other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetError()).compareTo(other.isSetError()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetError()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.error, other.error); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetData()).compareTo(other.isSetData()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetData()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.data, other.data); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetApp_id()).compareTo(other.isSetApp_id()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetApp_id()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.app_id, other.app_id); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetPartition_index()).compareTo(other.isSetPartition_index()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetPartition_index()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.partition_index, other.partition_index); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetServer()).compareTo(other.isSetServer()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetServer()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.server, other.server); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("batch_get_response("); + boolean first = true; + + sb.append("error:"); + sb.append(this.error); + first = false; + if (!first) sb.append(", "); + sb.append("data:"); + if (this.data == null) { + sb.append("null"); + } else { + sb.append(this.data); + } + first = false; + if (!first) sb.append(", "); + sb.append("app_id:"); + sb.append(this.app_id); + first = false; + if (!first) sb.append(", "); + sb.append("partition_index:"); + sb.append(this.partition_index); + first = false; + if (!first) sb.append(", "); + sb.append("server:"); + if (this.server == null) { + sb.append("null"); + } else { + sb.append(this.server); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + __isset_bitfield = 0; + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class batch_get_responseStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public batch_get_responseStandardScheme getScheme() { + return new batch_get_responseStandardScheme(); + } + } + + private static class batch_get_responseStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, batch_get_response struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // ERROR + if (schemeField.type == org.apache.thrift.protocol.TType.I32) { + struct.error = iprot.readI32(); + struct.setErrorIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // DATA + if (schemeField.type == org.apache.thrift.protocol.TType.LIST) { + { + org.apache.thrift.protocol.TList _list40 = iprot.readListBegin(); + struct.data = new java.util.ArrayList(_list40.size); + full_data _elem41; + for (int _i42 = 0; _i42 < _list40.size; ++_i42) + { + _elem41 = new full_data(); + _elem41.read(iprot); + struct.data.add(_elem41); + } + iprot.readListEnd(); + } + struct.setDataIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 3: // APP_ID + if (schemeField.type == org.apache.thrift.protocol.TType.I32) { + struct.app_id = iprot.readI32(); + struct.setApp_idIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 4: // PARTITION_INDEX + if (schemeField.type == org.apache.thrift.protocol.TType.I32) { + struct.partition_index = iprot.readI32(); + struct.setPartition_indexIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 6: // SERVER + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.server = iprot.readString(); + struct.setServerIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, batch_get_response struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldBegin(ERROR_FIELD_DESC); + oprot.writeI32(struct.error); + oprot.writeFieldEnd(); + if (struct.data != null) { + oprot.writeFieldBegin(DATA_FIELD_DESC); + { + oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, struct.data.size())); + for (full_data _iter43 : struct.data) + { + _iter43.write(oprot); + } + oprot.writeListEnd(); + } + oprot.writeFieldEnd(); + } + oprot.writeFieldBegin(APP_ID_FIELD_DESC); + oprot.writeI32(struct.app_id); + oprot.writeFieldEnd(); + oprot.writeFieldBegin(PARTITION_INDEX_FIELD_DESC); + oprot.writeI32(struct.partition_index); + oprot.writeFieldEnd(); + if (struct.server != null) { + oprot.writeFieldBegin(SERVER_FIELD_DESC); + oprot.writeString(struct.server); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class batch_get_responseTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public batch_get_responseTupleScheme getScheme() { + return new batch_get_responseTupleScheme(); + } + } + + private static class batch_get_responseTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, batch_get_response struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetError()) { + optionals.set(0); + } + if (struct.isSetData()) { + optionals.set(1); + } + if (struct.isSetApp_id()) { + optionals.set(2); + } + if (struct.isSetPartition_index()) { + optionals.set(3); + } + if (struct.isSetServer()) { + optionals.set(4); + } + oprot.writeBitSet(optionals, 5); + if (struct.isSetError()) { + oprot.writeI32(struct.error); + } + if (struct.isSetData()) { + { + oprot.writeI32(struct.data.size()); + for (full_data _iter44 : struct.data) + { + _iter44.write(oprot); + } + } + } + if (struct.isSetApp_id()) { + oprot.writeI32(struct.app_id); + } + if (struct.isSetPartition_index()) { + oprot.writeI32(struct.partition_index); + } + if (struct.isSetServer()) { + oprot.writeString(struct.server); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, batch_get_response struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(5); + if (incoming.get(0)) { + struct.error = iprot.readI32(); + struct.setErrorIsSet(true); + } + if (incoming.get(1)) { + { + org.apache.thrift.protocol.TList _list45 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32()); + struct.data = new java.util.ArrayList(_list45.size); + full_data _elem46; + for (int _i47 = 0; _i47 < _list45.size; ++_i47) + { + _elem46 = new full_data(); + _elem46.read(iprot); + struct.data.add(_elem46); + } + } + struct.setDataIsSet(true); + } + if (incoming.get(2)) { + struct.app_id = iprot.readI32(); + struct.setApp_idIsSet(true); + } + if (incoming.get(3)) { + struct.partition_index = iprot.readI32(); + struct.setPartition_indexIsSet(true); + } + if (incoming.get(4)) { + struct.server = iprot.readString(); + struct.setServerIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } +} + diff --git a/src/main/java/com/xiaomi/infra/pegasus/apps/full_data.java b/src/main/java/com/xiaomi/infra/pegasus/apps/full_data.java new file mode 100644 index 0000000000..cd45204d41 --- /dev/null +++ b/src/main/java/com/xiaomi/infra/pegasus/apps/full_data.java @@ -0,0 +1,611 @@ +// 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. +/** + * Autogenerated by Thrift Compiler (0.11.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.xiaomi.infra.pegasus.apps; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.11.0)", date = "2022-02-12") +public class full_data implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("full_data"); + + private static final org.apache.thrift.protocol.TField HASH_KEY_FIELD_DESC = new org.apache.thrift.protocol.TField("hash_key", org.apache.thrift.protocol.TType.STRUCT, (short)1); + private static final org.apache.thrift.protocol.TField SORT_KEY_FIELD_DESC = new org.apache.thrift.protocol.TField("sort_key", org.apache.thrift.protocol.TType.STRUCT, (short)2); + private static final org.apache.thrift.protocol.TField VALUE_FIELD_DESC = new org.apache.thrift.protocol.TField("value", org.apache.thrift.protocol.TType.STRUCT, (short)3); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new full_dataStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new full_dataTupleSchemeFactory(); + + public com.xiaomi.infra.pegasus.base.blob hash_key; // required + public com.xiaomi.infra.pegasus.base.blob sort_key; // required + public com.xiaomi.infra.pegasus.base.blob value; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + HASH_KEY((short)1, "hash_key"), + SORT_KEY((short)2, "sort_key"), + VALUE((short)3, "value"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // HASH_KEY + return HASH_KEY; + case 2: // SORT_KEY + return SORT_KEY; + case 3: // VALUE + return VALUE; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.HASH_KEY, new org.apache.thrift.meta_data.FieldMetaData("hash_key", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, com.xiaomi.infra.pegasus.base.blob.class))); + tmpMap.put(_Fields.SORT_KEY, new org.apache.thrift.meta_data.FieldMetaData("sort_key", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, com.xiaomi.infra.pegasus.base.blob.class))); + tmpMap.put(_Fields.VALUE, new org.apache.thrift.meta_data.FieldMetaData("value", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, com.xiaomi.infra.pegasus.base.blob.class))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(full_data.class, metaDataMap); + } + + public full_data() { + } + + public full_data( + com.xiaomi.infra.pegasus.base.blob hash_key, + com.xiaomi.infra.pegasus.base.blob sort_key, + com.xiaomi.infra.pegasus.base.blob value) + { + this(); + this.hash_key = hash_key; + this.sort_key = sort_key; + this.value = value; + } + + /** + * Performs a deep copy on other. + */ + public full_data(full_data other) { + if (other.isSetHash_key()) { + this.hash_key = new com.xiaomi.infra.pegasus.base.blob(other.hash_key); + } + if (other.isSetSort_key()) { + this.sort_key = new com.xiaomi.infra.pegasus.base.blob(other.sort_key); + } + if (other.isSetValue()) { + this.value = new com.xiaomi.infra.pegasus.base.blob(other.value); + } + } + + public full_data deepCopy() { + return new full_data(this); + } + + @Override + public void clear() { + this.hash_key = null; + this.sort_key = null; + this.value = null; + } + + public com.xiaomi.infra.pegasus.base.blob getHash_key() { + return this.hash_key; + } + + public full_data setHash_key(com.xiaomi.infra.pegasus.base.blob hash_key) { + this.hash_key = hash_key; + return this; + } + + public void unsetHash_key() { + this.hash_key = null; + } + + /** Returns true if field hash_key is set (has been assigned a value) and false otherwise */ + public boolean isSetHash_key() { + return this.hash_key != null; + } + + public void setHash_keyIsSet(boolean value) { + if (!value) { + this.hash_key = null; + } + } + + public com.xiaomi.infra.pegasus.base.blob getSort_key() { + return this.sort_key; + } + + public full_data setSort_key(com.xiaomi.infra.pegasus.base.blob sort_key) { + this.sort_key = sort_key; + return this; + } + + public void unsetSort_key() { + this.sort_key = null; + } + + /** Returns true if field sort_key is set (has been assigned a value) and false otherwise */ + public boolean isSetSort_key() { + return this.sort_key != null; + } + + public void setSort_keyIsSet(boolean value) { + if (!value) { + this.sort_key = null; + } + } + + public com.xiaomi.infra.pegasus.base.blob getValue() { + return this.value; + } + + public full_data setValue(com.xiaomi.infra.pegasus.base.blob value) { + this.value = value; + return this; + } + + public void unsetValue() { + this.value = null; + } + + /** Returns true if field value is set (has been assigned a value) and false otherwise */ + public boolean isSetValue() { + return this.value != null; + } + + public void setValueIsSet(boolean value) { + if (!value) { + this.value = null; + } + } + + public void setFieldValue(_Fields field, java.lang.Object value) { + switch (field) { + case HASH_KEY: + if (value == null) { + unsetHash_key(); + } else { + setHash_key((com.xiaomi.infra.pegasus.base.blob)value); + } + break; + + case SORT_KEY: + if (value == null) { + unsetSort_key(); + } else { + setSort_key((com.xiaomi.infra.pegasus.base.blob)value); + } + break; + + case VALUE: + if (value == null) { + unsetValue(); + } else { + setValue((com.xiaomi.infra.pegasus.base.blob)value); + } + break; + + } + } + + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case HASH_KEY: + return getHash_key(); + + case SORT_KEY: + return getSort_key(); + + case VALUE: + return getValue(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case HASH_KEY: + return isSetHash_key(); + case SORT_KEY: + return isSetSort_key(); + case VALUE: + return isSetValue(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof full_data) + return this.equals((full_data)that); + return false; + } + + public boolean equals(full_data that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_hash_key = true && this.isSetHash_key(); + boolean that_present_hash_key = true && that.isSetHash_key(); + if (this_present_hash_key || that_present_hash_key) { + if (!(this_present_hash_key && that_present_hash_key)) + return false; + if (!this.hash_key.equals(that.hash_key)) + return false; + } + + boolean this_present_sort_key = true && this.isSetSort_key(); + boolean that_present_sort_key = true && that.isSetSort_key(); + if (this_present_sort_key || that_present_sort_key) { + if (!(this_present_sort_key && that_present_sort_key)) + return false; + if (!this.sort_key.equals(that.sort_key)) + return false; + } + + boolean this_present_value = true && this.isSetValue(); + boolean that_present_value = true && that.isSetValue(); + if (this_present_value || that_present_value) { + if (!(this_present_value && that_present_value)) + return false; + if (!this.value.equals(that.value)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetHash_key()) ? 131071 : 524287); + if (isSetHash_key()) + hashCode = hashCode * 8191 + hash_key.hashCode(); + + hashCode = hashCode * 8191 + ((isSetSort_key()) ? 131071 : 524287); + if (isSetSort_key()) + hashCode = hashCode * 8191 + sort_key.hashCode(); + + hashCode = hashCode * 8191 + ((isSetValue()) ? 131071 : 524287); + if (isSetValue()) + hashCode = hashCode * 8191 + value.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(full_data other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetHash_key()).compareTo(other.isSetHash_key()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetHash_key()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.hash_key, other.hash_key); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetSort_key()).compareTo(other.isSetSort_key()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetSort_key()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.sort_key, other.sort_key); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetValue()).compareTo(other.isSetValue()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetValue()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.value, other.value); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("full_data("); + boolean first = true; + + sb.append("hash_key:"); + if (this.hash_key == null) { + sb.append("null"); + } else { + sb.append(this.hash_key); + } + first = false; + if (!first) sb.append(", "); + sb.append("sort_key:"); + if (this.sort_key == null) { + sb.append("null"); + } else { + sb.append(this.sort_key); + } + first = false; + if (!first) sb.append(", "); + sb.append("value:"); + if (this.value == null) { + sb.append("null"); + } else { + sb.append(this.value); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + if (hash_key != null) { + hash_key.validate(); + } + if (sort_key != null) { + sort_key.validate(); + } + if (value != null) { + value.validate(); + } + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class full_dataStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public full_dataStandardScheme getScheme() { + return new full_dataStandardScheme(); + } + } + + private static class full_dataStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, full_data struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // HASH_KEY + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.hash_key = new com.xiaomi.infra.pegasus.base.blob(); + struct.hash_key.read(iprot); + struct.setHash_keyIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // SORT_KEY + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.sort_key = new com.xiaomi.infra.pegasus.base.blob(); + struct.sort_key.read(iprot); + struct.setSort_keyIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 3: // VALUE + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.value = new com.xiaomi.infra.pegasus.base.blob(); + struct.value.read(iprot); + struct.setValueIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, full_data struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.hash_key != null) { + oprot.writeFieldBegin(HASH_KEY_FIELD_DESC); + struct.hash_key.write(oprot); + oprot.writeFieldEnd(); + } + if (struct.sort_key != null) { + oprot.writeFieldBegin(SORT_KEY_FIELD_DESC); + struct.sort_key.write(oprot); + oprot.writeFieldEnd(); + } + if (struct.value != null) { + oprot.writeFieldBegin(VALUE_FIELD_DESC); + struct.value.write(oprot); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class full_dataTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public full_dataTupleScheme getScheme() { + return new full_dataTupleScheme(); + } + } + + private static class full_dataTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, full_data struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetHash_key()) { + optionals.set(0); + } + if (struct.isSetSort_key()) { + optionals.set(1); + } + if (struct.isSetValue()) { + optionals.set(2); + } + oprot.writeBitSet(optionals, 3); + if (struct.isSetHash_key()) { + struct.hash_key.write(oprot); + } + if (struct.isSetSort_key()) { + struct.sort_key.write(oprot); + } + if (struct.isSetValue()) { + struct.value.write(oprot); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, full_data struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(3); + if (incoming.get(0)) { + struct.hash_key = new com.xiaomi.infra.pegasus.base.blob(); + struct.hash_key.read(iprot); + struct.setHash_keyIsSet(true); + } + if (incoming.get(1)) { + struct.sort_key = new com.xiaomi.infra.pegasus.base.blob(); + struct.sort_key.read(iprot); + struct.setSort_keyIsSet(true); + } + if (incoming.get(2)) { + struct.value = new com.xiaomi.infra.pegasus.base.blob(); + struct.value.read(iprot); + struct.setValueIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } +} + diff --git a/src/main/java/com/xiaomi/infra/pegasus/apps/full_key.java b/src/main/java/com/xiaomi/infra/pegasus/apps/full_key.java new file mode 100644 index 0000000000..8472ebb649 --- /dev/null +++ b/src/main/java/com/xiaomi/infra/pegasus/apps/full_key.java @@ -0,0 +1,502 @@ +// 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. +/** + * Autogenerated by Thrift Compiler (0.11.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.xiaomi.infra.pegasus.apps; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.11.0)", date = "2022-02-12") +public class full_key implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("full_key"); + + private static final org.apache.thrift.protocol.TField HASH_KEY_FIELD_DESC = new org.apache.thrift.protocol.TField("hash_key", org.apache.thrift.protocol.TType.STRUCT, (short)1); + private static final org.apache.thrift.protocol.TField SORT_KEY_FIELD_DESC = new org.apache.thrift.protocol.TField("sort_key", org.apache.thrift.protocol.TType.STRUCT, (short)2); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new full_keyStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new full_keyTupleSchemeFactory(); + + public com.xiaomi.infra.pegasus.base.blob hash_key; // required + public com.xiaomi.infra.pegasus.base.blob sort_key; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + HASH_KEY((short)1, "hash_key"), + SORT_KEY((short)2, "sort_key"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // HASH_KEY + return HASH_KEY; + case 2: // SORT_KEY + return SORT_KEY; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.HASH_KEY, new org.apache.thrift.meta_data.FieldMetaData("hash_key", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, com.xiaomi.infra.pegasus.base.blob.class))); + tmpMap.put(_Fields.SORT_KEY, new org.apache.thrift.meta_data.FieldMetaData("sort_key", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, com.xiaomi.infra.pegasus.base.blob.class))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(full_key.class, metaDataMap); + } + + public full_key() { + } + + public full_key( + com.xiaomi.infra.pegasus.base.blob hash_key, + com.xiaomi.infra.pegasus.base.blob sort_key) + { + this(); + this.hash_key = hash_key; + this.sort_key = sort_key; + } + + /** + * Performs a deep copy on other. + */ + public full_key(full_key other) { + if (other.isSetHash_key()) { + this.hash_key = new com.xiaomi.infra.pegasus.base.blob(other.hash_key); + } + if (other.isSetSort_key()) { + this.sort_key = new com.xiaomi.infra.pegasus.base.blob(other.sort_key); + } + } + + public full_key deepCopy() { + return new full_key(this); + } + + @Override + public void clear() { + this.hash_key = null; + this.sort_key = null; + } + + public com.xiaomi.infra.pegasus.base.blob getHash_key() { + return this.hash_key; + } + + public full_key setHash_key(com.xiaomi.infra.pegasus.base.blob hash_key) { + this.hash_key = hash_key; + return this; + } + + public void unsetHash_key() { + this.hash_key = null; + } + + /** Returns true if field hash_key is set (has been assigned a value) and false otherwise */ + public boolean isSetHash_key() { + return this.hash_key != null; + } + + public void setHash_keyIsSet(boolean value) { + if (!value) { + this.hash_key = null; + } + } + + public com.xiaomi.infra.pegasus.base.blob getSort_key() { + return this.sort_key; + } + + public full_key setSort_key(com.xiaomi.infra.pegasus.base.blob sort_key) { + this.sort_key = sort_key; + return this; + } + + public void unsetSort_key() { + this.sort_key = null; + } + + /** Returns true if field sort_key is set (has been assigned a value) and false otherwise */ + public boolean isSetSort_key() { + return this.sort_key != null; + } + + public void setSort_keyIsSet(boolean value) { + if (!value) { + this.sort_key = null; + } + } + + public void setFieldValue(_Fields field, java.lang.Object value) { + switch (field) { + case HASH_KEY: + if (value == null) { + unsetHash_key(); + } else { + setHash_key((com.xiaomi.infra.pegasus.base.blob)value); + } + break; + + case SORT_KEY: + if (value == null) { + unsetSort_key(); + } else { + setSort_key((com.xiaomi.infra.pegasus.base.blob)value); + } + break; + + } + } + + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case HASH_KEY: + return getHash_key(); + + case SORT_KEY: + return getSort_key(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case HASH_KEY: + return isSetHash_key(); + case SORT_KEY: + return isSetSort_key(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof full_key) + return this.equals((full_key)that); + return false; + } + + public boolean equals(full_key that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_hash_key = true && this.isSetHash_key(); + boolean that_present_hash_key = true && that.isSetHash_key(); + if (this_present_hash_key || that_present_hash_key) { + if (!(this_present_hash_key && that_present_hash_key)) + return false; + if (!this.hash_key.equals(that.hash_key)) + return false; + } + + boolean this_present_sort_key = true && this.isSetSort_key(); + boolean that_present_sort_key = true && that.isSetSort_key(); + if (this_present_sort_key || that_present_sort_key) { + if (!(this_present_sort_key && that_present_sort_key)) + return false; + if (!this.sort_key.equals(that.sort_key)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetHash_key()) ? 131071 : 524287); + if (isSetHash_key()) + hashCode = hashCode * 8191 + hash_key.hashCode(); + + hashCode = hashCode * 8191 + ((isSetSort_key()) ? 131071 : 524287); + if (isSetSort_key()) + hashCode = hashCode * 8191 + sort_key.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(full_key other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetHash_key()).compareTo(other.isSetHash_key()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetHash_key()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.hash_key, other.hash_key); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetSort_key()).compareTo(other.isSetSort_key()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetSort_key()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.sort_key, other.sort_key); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("full_key("); + boolean first = true; + + sb.append("hash_key:"); + if (this.hash_key == null) { + sb.append("null"); + } else { + sb.append(this.hash_key); + } + first = false; + if (!first) sb.append(", "); + sb.append("sort_key:"); + if (this.sort_key == null) { + sb.append("null"); + } else { + sb.append(this.sort_key); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + if (hash_key != null) { + hash_key.validate(); + } + if (sort_key != null) { + sort_key.validate(); + } + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class full_keyStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public full_keyStandardScheme getScheme() { + return new full_keyStandardScheme(); + } + } + + private static class full_keyStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, full_key struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // HASH_KEY + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.hash_key = new com.xiaomi.infra.pegasus.base.blob(); + struct.hash_key.read(iprot); + struct.setHash_keyIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // SORT_KEY + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.sort_key = new com.xiaomi.infra.pegasus.base.blob(); + struct.sort_key.read(iprot); + struct.setSort_keyIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, full_key struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.hash_key != null) { + oprot.writeFieldBegin(HASH_KEY_FIELD_DESC); + struct.hash_key.write(oprot); + oprot.writeFieldEnd(); + } + if (struct.sort_key != null) { + oprot.writeFieldBegin(SORT_KEY_FIELD_DESC); + struct.sort_key.write(oprot); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class full_keyTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public full_keyTupleScheme getScheme() { + return new full_keyTupleScheme(); + } + } + + private static class full_keyTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, full_key struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetHash_key()) { + optionals.set(0); + } + if (struct.isSetSort_key()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetHash_key()) { + struct.hash_key.write(oprot); + } + if (struct.isSetSort_key()) { + struct.sort_key.write(oprot); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, full_key struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + struct.hash_key = new com.xiaomi.infra.pegasus.base.blob(); + struct.hash_key.read(iprot); + struct.setHash_keyIsSet(true); + } + if (incoming.get(1)) { + struct.sort_key = new com.xiaomi.infra.pegasus.base.blob(); + struct.sort_key.read(iprot); + struct.setSort_keyIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } +} + diff --git a/src/main/java/com/xiaomi/infra/pegasus/apps/rrdb.java b/src/main/java/com/xiaomi/infra/pegasus/apps/rrdb.java index 37b62b495d..d58b201c6f 100644 --- a/src/main/java/com/xiaomi/infra/pegasus/apps/rrdb.java +++ b/src/main/java/com/xiaomi/infra/pegasus/apps/rrdb.java @@ -1,6 +1,19 @@ -// Copyright (c) 2017, Xiaomi, Inc. All rights reserved. -// This source code is licensed under the Apache License Version 2.0, which -// can be found in the LICENSE file in the root directory of this source tree. +// 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. /** * Autogenerated by Thrift Compiler (0.11.0) * @@ -10,7 +23,7 @@ package com.xiaomi.infra.pegasus.apps; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) -@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.11.0)", date = "2020-04-13") +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.11.0)", date = "2022-02-12") public class rrdb { public interface Iface { @@ -33,6 +46,8 @@ public interface Iface { public multi_get_response multi_get(multi_get_request request) throws org.apache.thrift.TException; + public batch_get_response batch_get(batch_get_request request) throws org.apache.thrift.TException; + public count_response sortkey_count(com.xiaomi.infra.pegasus.base.blob hash_key) throws org.apache.thrift.TException; public ttl_response ttl(com.xiaomi.infra.pegasus.base.blob key) throws org.apache.thrift.TException; @@ -65,6 +80,8 @@ public interface AsyncIface { public void multi_get(multi_get_request request, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + public void batch_get(batch_get_request request, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + public void sortkey_count(com.xiaomi.infra.pegasus.base.blob hash_key, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; public void ttl(com.xiaomi.infra.pegasus.base.blob key, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; @@ -304,6 +321,29 @@ public multi_get_response recv_multi_get() throws org.apache.thrift.TException throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "multi_get failed: unknown result"); } + public batch_get_response batch_get(batch_get_request request) throws org.apache.thrift.TException + { + send_batch_get(request); + return recv_batch_get(); + } + + public void send_batch_get(batch_get_request request) throws org.apache.thrift.TException + { + batch_get_args args = new batch_get_args(); + args.setRequest(request); + sendBase("batch_get", args); + } + + public batch_get_response recv_batch_get() throws org.apache.thrift.TException + { + batch_get_result result = new batch_get_result(); + receiveBase(result, "batch_get"); + if (result.isSetSuccess()) { + return result.success; + } + throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "batch_get failed: unknown result"); + } + public count_response sortkey_count(com.xiaomi.infra.pegasus.base.blob hash_key) throws org.apache.thrift.TException { send_sortkey_count(hash_key); @@ -714,6 +754,38 @@ public multi_get_response getResult() throws org.apache.thrift.TException { } } + public void batch_get(batch_get_request request, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + checkReady(); + batch_get_call method_call = new batch_get_call(request, resultHandler, this, ___protocolFactory, ___transport); + this.___currentMethod = method_call; + ___manager.call(method_call); + } + + public static class batch_get_call extends org.apache.thrift.async.TAsyncMethodCall { + private batch_get_request request; + public batch_get_call(batch_get_request request, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { + super(client, protocolFactory, transport, resultHandler, false); + this.request = request; + } + + public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { + prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("batch_get", org.apache.thrift.protocol.TMessageType.CALL, 0)); + batch_get_args args = new batch_get_args(); + args.setRequest(request); + args.write(prot); + prot.writeMessageEnd(); + } + + public batch_get_response getResult() throws org.apache.thrift.TException { + if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { + throw new java.lang.IllegalStateException("Method call not finished!"); + } + org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); + org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); + return (new Client(prot)).recv_batch_get(); + } + } + public void sortkey_count(com.xiaomi.infra.pegasus.base.blob hash_key, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { checkReady(); sortkey_count_call method_call = new sortkey_count_call(hash_key, resultHandler, this, ___protocolFactory, ___transport); @@ -896,6 +968,7 @@ protected Processor(I iface, java.util.Map extends org.apache.thrift.ProcessFunction { + public batch_get() { + super("batch_get"); + } + + public batch_get_args getEmptyArgsInstance() { + return new batch_get_args(); + } + + protected boolean isOneway() { + return false; + } + + @Override + protected boolean handleRuntimeExceptions() { + return false; + } + + public batch_get_result getResult(I iface, batch_get_args args) throws org.apache.thrift.TException { + batch_get_result result = new batch_get_result(); + result.success = iface.batch_get(args.request); + return result; + } + } + public static class sortkey_count extends org.apache.thrift.ProcessFunction { public sortkey_count() { super("sortkey_count"); @@ -1275,6 +1373,7 @@ protected AsyncProcessor(I iface, java.util.Map extends org.apache.thrift.AsyncProcessFunction { + public batch_get() { + super("batch_get"); + } + + public batch_get_args getEmptyArgsInstance() { + return new batch_get_args(); + } + + public org.apache.thrift.async.AsyncMethodCallback getResultHandler(final org.apache.thrift.server.AbstractNonblockingServer.AsyncFrameBuffer fb, final int seqid) { + final org.apache.thrift.AsyncProcessFunction fcall = this; + return new org.apache.thrift.async.AsyncMethodCallback() { + public void onComplete(batch_get_response o) { + batch_get_result result = new batch_get_result(); + result.success = o; + try { + fcall.sendResponse(fb, result, org.apache.thrift.protocol.TMessageType.REPLY,seqid); + } catch (org.apache.thrift.transport.TTransportException e) { + _LOGGER.error("TTransportException writing to internal frame buffer", e); + fb.close(); + } catch (java.lang.Exception e) { + _LOGGER.error("Exception writing to internal frame buffer", e); + onError(e); + } + } + public void onError(java.lang.Exception e) { + byte msgType = org.apache.thrift.protocol.TMessageType.REPLY; + org.apache.thrift.TSerializable msg; + batch_get_result result = new batch_get_result(); + if (e instanceof org.apache.thrift.transport.TTransportException) { + _LOGGER.error("TTransportException inside handler", e); + fb.close(); + return; + } else if (e instanceof org.apache.thrift.TApplicationException) { + _LOGGER.error("TApplicationException inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = (org.apache.thrift.TApplicationException)e; + } else { + _LOGGER.error("Exception inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage()); + } + try { + fcall.sendResponse(fb,msg,msgType,seqid); + } catch (java.lang.Exception ex) { + _LOGGER.error("Exception writing to internal frame buffer", ex); + fb.close(); + } + } + }; + } + + protected boolean isOneway() { + return false; + } + + public void start(I iface, batch_get_args args, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + iface.batch_get(args.request,resultHandler); + } + } + public static class sortkey_count extends org.apache.thrift.AsyncProcessFunction { public sortkey_count() { super("sortkey_count"); @@ -8718,6 +8878,740 @@ private static S scheme(org.apache. } } + public static class batch_get_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("batch_get_args"); + + private static final org.apache.thrift.protocol.TField REQUEST_FIELD_DESC = new org.apache.thrift.protocol.TField("request", org.apache.thrift.protocol.TType.STRUCT, (short)1); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new batch_get_argsStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new batch_get_argsTupleSchemeFactory(); + + public batch_get_request request; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + REQUEST((short)1, "request"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // REQUEST + return REQUEST; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.REQUEST, new org.apache.thrift.meta_data.FieldMetaData("request", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, batch_get_request.class))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(batch_get_args.class, metaDataMap); + } + + public batch_get_args() { + } + + public batch_get_args( + batch_get_request request) + { + this(); + this.request = request; + } + + /** + * Performs a deep copy on other. + */ + public batch_get_args(batch_get_args other) { + if (other.isSetRequest()) { + this.request = new batch_get_request(other.request); + } + } + + public batch_get_args deepCopy() { + return new batch_get_args(this); + } + + @Override + public void clear() { + this.request = null; + } + + public batch_get_request getRequest() { + return this.request; + } + + public batch_get_args setRequest(batch_get_request request) { + this.request = request; + return this; + } + + public void unsetRequest() { + this.request = null; + } + + /** Returns true if field request is set (has been assigned a value) and false otherwise */ + public boolean isSetRequest() { + return this.request != null; + } + + public void setRequestIsSet(boolean value) { + if (!value) { + this.request = null; + } + } + + public void setFieldValue(_Fields field, java.lang.Object value) { + switch (field) { + case REQUEST: + if (value == null) { + unsetRequest(); + } else { + setRequest((batch_get_request)value); + } + break; + + } + } + + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case REQUEST: + return getRequest(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case REQUEST: + return isSetRequest(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof batch_get_args) + return this.equals((batch_get_args)that); + return false; + } + + public boolean equals(batch_get_args that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_request = true && this.isSetRequest(); + boolean that_present_request = true && that.isSetRequest(); + if (this_present_request || that_present_request) { + if (!(this_present_request && that_present_request)) + return false; + if (!this.request.equals(that.request)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetRequest()) ? 131071 : 524287); + if (isSetRequest()) + hashCode = hashCode * 8191 + request.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(batch_get_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetRequest()).compareTo(other.isSetRequest()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetRequest()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.request, other.request); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("batch_get_args("); + boolean first = true; + + sb.append("request:"); + if (this.request == null) { + sb.append("null"); + } else { + sb.append(this.request); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + if (request != null) { + request.validate(); + } + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class batch_get_argsStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public batch_get_argsStandardScheme getScheme() { + return new batch_get_argsStandardScheme(); + } + } + + private static class batch_get_argsStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, batch_get_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // REQUEST + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.request = new batch_get_request(); + struct.request.read(iprot); + struct.setRequestIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, batch_get_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.request != null) { + oprot.writeFieldBegin(REQUEST_FIELD_DESC); + struct.request.write(oprot); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class batch_get_argsTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public batch_get_argsTupleScheme getScheme() { + return new batch_get_argsTupleScheme(); + } + } + + private static class batch_get_argsTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, batch_get_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetRequest()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetRequest()) { + struct.request.write(oprot); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, batch_get_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + struct.request = new batch_get_request(); + struct.request.read(iprot); + struct.setRequestIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + + public static class batch_get_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("batch_get_result"); + + private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.STRUCT, (short)0); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new batch_get_resultStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new batch_get_resultTupleSchemeFactory(); + + public batch_get_response success; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + SUCCESS((short)0, "success"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 0: // SUCCESS + return SUCCESS; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.SUCCESS, new org.apache.thrift.meta_data.FieldMetaData("success", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, batch_get_response.class))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(batch_get_result.class, metaDataMap); + } + + public batch_get_result() { + } + + public batch_get_result( + batch_get_response success) + { + this(); + this.success = success; + } + + /** + * Performs a deep copy on other. + */ + public batch_get_result(batch_get_result other) { + if (other.isSetSuccess()) { + this.success = new batch_get_response(other.success); + } + } + + public batch_get_result deepCopy() { + return new batch_get_result(this); + } + + @Override + public void clear() { + this.success = null; + } + + public batch_get_response getSuccess() { + return this.success; + } + + public batch_get_result setSuccess(batch_get_response success) { + this.success = success; + return this; + } + + public void unsetSuccess() { + this.success = null; + } + + /** Returns true if field success is set (has been assigned a value) and false otherwise */ + public boolean isSetSuccess() { + return this.success != null; + } + + public void setSuccessIsSet(boolean value) { + if (!value) { + this.success = null; + } + } + + public void setFieldValue(_Fields field, java.lang.Object value) { + switch (field) { + case SUCCESS: + if (value == null) { + unsetSuccess(); + } else { + setSuccess((batch_get_response)value); + } + break; + + } + } + + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case SUCCESS: + return getSuccess(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case SUCCESS: + return isSetSuccess(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof batch_get_result) + return this.equals((batch_get_result)that); + return false; + } + + public boolean equals(batch_get_result that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_success = true && this.isSetSuccess(); + boolean that_present_success = true && that.isSetSuccess(); + if (this_present_success || that_present_success) { + if (!(this_present_success && that_present_success)) + return false; + if (!this.success.equals(that.success)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetSuccess()) ? 131071 : 524287); + if (isSetSuccess()) + hashCode = hashCode * 8191 + success.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(batch_get_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetSuccess()).compareTo(other.isSetSuccess()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetSuccess()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, other.success); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("batch_get_result("); + boolean first = true; + + sb.append("success:"); + if (this.success == null) { + sb.append("null"); + } else { + sb.append(this.success); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + if (success != null) { + success.validate(); + } + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class batch_get_resultStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public batch_get_resultStandardScheme getScheme() { + return new batch_get_resultStandardScheme(); + } + } + + private static class batch_get_resultStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, batch_get_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 0: // SUCCESS + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.success = new batch_get_response(); + struct.success.read(iprot); + struct.setSuccessIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, batch_get_result struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.success != null) { + oprot.writeFieldBegin(SUCCESS_FIELD_DESC); + struct.success.write(oprot); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class batch_get_resultTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public batch_get_resultTupleScheme getScheme() { + return new batch_get_resultTupleScheme(); + } + } + + private static class batch_get_resultTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, batch_get_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetSuccess()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetSuccess()) { + struct.success.write(oprot); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, batch_get_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + struct.success = new batch_get_response(); + struct.success.read(iprot); + struct.setSuccessIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + public static class sortkey_count_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("sortkey_count_args"); diff --git a/src/main/java/com/xiaomi/infra/pegasus/client/PegasusClient.java b/src/main/java/com/xiaomi/infra/pegasus/client/PegasusClient.java index a188cf6b9a..31f02216cf 100644 --- a/src/main/java/com/xiaomi/infra/pegasus/client/PegasusClient.java +++ b/src/main/java/com/xiaomi/infra/pegasus/client/PegasusClient.java @@ -248,6 +248,14 @@ public int batchGet2( return tb.batchGet2(keys, values, 0); } + @Override + public int batchGetByPartitions( + String tableName, List> keys, List> values) + throws PException { + PegasusTable tb = getTable(tableName); + return tb.batchGetByPartitions(keys, values, 0); + } + @Override public boolean multiGet( String tableName, diff --git a/src/main/java/com/xiaomi/infra/pegasus/client/PegasusClientInterface.java b/src/main/java/com/xiaomi/infra/pegasus/client/PegasusClientInterface.java index 529580c2b9..b296d761e0 100644 --- a/src/main/java/com/xiaomi/infra/pegasus/client/PegasusClientInterface.java +++ b/src/main/java/com/xiaomi/infra/pegasus/client/PegasusClientInterface.java @@ -149,6 +149,10 @@ public int batchGet2( String tableName, List> keys, List> results) throws PException; + public int batchGetByPartitions( + String tableName, List> keys, List> results) + throws PException; + /** * Get multiple values under the same hash key. * diff --git a/src/main/java/com/xiaomi/infra/pegasus/client/PegasusTable.java b/src/main/java/com/xiaomi/infra/pegasus/client/PegasusTable.java index c017e2b4db..859d240fc6 100644 --- a/src/main/java/com/xiaomi/infra/pegasus/client/PegasusTable.java +++ b/src/main/java/com/xiaomi/infra/pegasus/client/PegasusTable.java @@ -399,6 +399,57 @@ public Future asyncMultiGetSortKeys(byte[] hashKey, int return asyncMultiGetSortKeys(hashKey, -1, -1, timeout); } + @Override + public Future asyncBatchGet(batch_get_request request, int timeout) { + final DefaultPromise promise = table.newPromise(); + if (request.keys.isEmpty()) { + promise.setFailure(new PException("Invalid parameter: hashKey should not be null or empty")); + return promise; + } + for (full_key fullKey : request.keys) { + blob key = fullKey.hash_key; + if (key.data.length >= 0xFFFF) { + promise.setFailure( + new PException("Invalid parameter: hashKey length should be less than UINT16_MAX")); + return promise; + } + } + + long partitionHash = table.getKeyHash(request.keys.get(0).hash_key.data); + gpid gpid = table.getGpidByHash(partitionHash); + batch_get_operator op = + new batch_get_operator(gpid, table.getTableName(), request, partitionHash); + + table.asyncOperate( + op, + new Table.ClientOPCallback() { + @Override + public void onCompletion(client_operator clientOP) { + batch_get_operator gop = (batch_get_operator) clientOP; + if (gop.rpc_error.errno != error_code.error_types.ERR_OK) { + handleReplicaException( + new Request(request.keys.get(0).hash_key.data), promise, op, table, timeout); + } else if (gop.get_response().error != 0 && gop.get_response().error != 7) { + // rocksdb::Status::kOk && rocksdb::Status::kIncomplete + promise.setFailure(new PException("rocksdb error: " + gop.get_response().error)); + } else { + BatchGetResult result = new BatchGetResult(); + result.allFetched = (gop.get_response().error == 0); + result.valueMap = new HashMap<>(); + for (full_data data : gop.get_response().data) { + result.valueMap.put( + Pair.of(new String(data.hash_key.data), new String(data.sort_key.data)), + data.value.data); + } + + promise.setSuccess(result); + } + } + }, + timeout); + return promise; + } + @Override public Future asyncMultiSet( byte[] hashKey, List> values, int ttlSeconds, int timeout) { @@ -985,6 +1036,91 @@ public void batchGet(List> keys, List values, int t } } + @Override + public int batchGetByPartitions( + List> keys, List> results, int timeout) + throws PException { + if (keys == null || keys.size() == 0) { + throw new PException("Invalid parameter: keys should not be null or empty"); + } + if (results == null) { + throw new PException("Invalid parameter: results should not be null"); + } + results.clear(); + List> futures = new ArrayList>(); + + // Group By Partition Index Id + List requestList = new ArrayList(); + List partitionToPException = new ArrayList<>(); + for (int i = 0; i < this.table.getPartitionCount(); i++) { + batch_get_request templateRequest = new batch_get_request(); + templateRequest.keys = new ArrayList<>(); + requestList.add(templateRequest); + partitionToPException.add(null); + } + + List responseIndex = new ArrayList<>(); + for (Pair k : keys) { + byte[] hashKey = k.getLeft(); + byte[] sortKey = k.getRight(); + + long partitionHash = table.getKeyHash(hashKey); + gpid gpid = table.getGpidByHash(partitionHash); + batch_get_request r = requestList.get(gpid.get_pidx()); + responseIndex.add(gpid.get_pidx()); + + full_key fullKey = new full_key(); + fullKey.hash_key = new blob(hashKey); + fullKey.sort_key = new blob(sortKey); + r.keys.add(fullKey); + } + + for (int i = 0; i < requestList.size(); i++) { + batch_get_request request = requestList.get(i); + if (request.keys.isEmpty()) { + futures.add(null); + continue; + } + futures.add(asyncBatchGet(request, timeout)); + } + + List, byte[]>> resultMapList = new ArrayList<>(); + for (int i = 0; i < this.table.getPartitionCount(); i++) { + if (requestList.get(i).keys.isEmpty()) { + Map, byte[]> emptyMap = new HashMap<>(); + resultMapList.add(emptyMap); + continue; + } + Future fu = futures.get(i); + fu.awaitUninterruptibly(); + if (fu.isSuccess()) { + resultMapList.add(fu.getNow().valueMap); + } else { + Throwable cause = fu.cause(); + partitionToPException.set( + i, new PException("Get value of keys[" + i + "] failed: " + cause.getMessage(), cause)); + } + } + + int count = 0; + for (int i = 0; i < responseIndex.size(); i++) { + int index = responseIndex.get(i); + if (null != partitionToPException.get(index)) { + results.add(Pair.of(partitionToPException.get(index), null)); + continue; + } + + byte[] value = + resultMapList + .get(index) + .get(Pair.of(new String(keys.get(i).getLeft()), new String(keys.get(i).getRight()))); + results.add(Pair.of(null, value)); + + count++; + } + return count; + } + @Override public int batchGet2( List> keys, List> results, int timeout) diff --git a/src/main/java/com/xiaomi/infra/pegasus/client/PegasusTableInterface.java b/src/main/java/com/xiaomi/infra/pegasus/client/PegasusTableInterface.java index 35239209f6..7aa08015d6 100644 --- a/src/main/java/com/xiaomi/infra/pegasus/client/PegasusTableInterface.java +++ b/src/main/java/com/xiaomi/infra/pegasus/client/PegasusTableInterface.java @@ -3,9 +3,11 @@ // can be found in the LICENSE file in the root directory of this source tree. package com.xiaomi.infra.pegasus.client; +import com.xiaomi.infra.pegasus.apps.batch_get_request; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.GenericFutureListener; import java.util.List; +import java.util.Map; import org.apache.commons.lang3.tuple.Pair; /** @@ -172,6 +174,16 @@ public static class MultiGetResult { public List> values; } + public static class BatchGetResult { + /** + * @param allFetched true if all data on the server are fetched; false if only partial data are + * fetched. + */ + public boolean allFetched; + + public Map, byte[]> valueMap; + } + public static interface MultiGetListener extends GenericFutureListener> { /** * This function will be called when listened asyncMultiGet future is done. @@ -184,6 +196,21 @@ public static interface MultiGetListener extends GenericFutureListener future) throws Exception; } + /** + * @param request it contains a list of pair, which is related to one partition + * @param timeout how long will the operation timeout in milliseconds. if timeout > 0, it is a + * timeout value for current op, else the timeout value in the configuration file will be + * used. + * @return the future for current op + *

Future return: On success: An object of type BatchGetResult On failure: a throwable, + * which is an instance of PException + *

Thread safety: All the listeners for the same table are guaranteed to be dispatched in + * the same thread, so all the listeners for the same future are guaranteed to be executed as + * the same order as the listeners added. But listeners for different tables are not + * guaranteed to be dispatched in the same thread. + */ + public Future asyncBatchGet(batch_get_request request, int timeout); + /** * get multiple key-values under the same hashKey, async version * @@ -746,6 +773,26 @@ public static interface TTLListener extends GenericFutureListener> keys, List values, int timeout /*ms*/) throws PException; + /** + * Batch get values of different keys. Will wait for all requests done even if some error occurs. + * + * @param keys hashKey and sortKey pair list. + * @param results output results; should be created by caller; after call done, the size of + * results will be same with keys; the results[i] is a Pair: - if Pair.left != null : means + * query keys[i] failed, Pair.left is the exception. - if Pair.left == null : means query + * keys[i] succeed, Pair.right is the result value. + * @param timeout how long will the operation timeout in milliseconds. if timeout > 0, it is a + * timeout value for current op, else the timeout value in the configuration file will be + * used. + * @return succeed count. + * @throws PException throw exception if any error occurs. + *

Notice: the method is not atomic, that means, maybe some keys succeed but some keys + * failed. + */ + public int batchGetByPartitions( + List> keys, List> results, int timeout /*ms*/) + throws PException; + /** * Batch get values of different keys. Will wait for all requests done even if some error occurs. * diff --git a/src/main/java/com/xiaomi/infra/pegasus/operator/batch_get_operator.java b/src/main/java/com/xiaomi/infra/pegasus/operator/batch_get_operator.java new file mode 100644 index 0000000000..5314451735 --- /dev/null +++ b/src/main/java/com/xiaomi/infra/pegasus/operator/batch_get_operator.java @@ -0,0 +1,58 @@ +// Copyright (c) 2017, Xiaomi, Inc. All rights reserved. +// This source code is licensed under the Apache License Version 2.0, which +// can be found in the LICENSE file in the root directory of this source tree. + +package com.xiaomi.infra.pegasus.operator; + +import com.xiaomi.infra.pegasus.apps.batch_get_request; +import com.xiaomi.infra.pegasus.apps.batch_get_response; +import com.xiaomi.infra.pegasus.apps.rrdb; +import org.apache.thrift.TException; +import org.apache.thrift.protocol.TMessage; +import org.apache.thrift.protocol.TMessageType; +import org.apache.thrift.protocol.TProtocol; + +public class batch_get_operator extends client_operator { + private batch_get_request request; + private batch_get_response response; + + public batch_get_operator( + com.xiaomi.infra.pegasus.base.gpid gpid, + String tableName, + batch_get_request request, + long partitionHash) { + super(gpid, tableName, partitionHash); + this.request = request; + } + + @Override + public String name() { + return "batch_get"; + } + + @Override + public void send_data(TProtocol oprot, int sequence_id) throws TException { + TMessage msg = new TMessage("RPC_RRDB_RRDB_BATCH_GET", TMessageType.CALL, sequence_id); + oprot.writeMessageBegin(msg); + rrdb.batch_get_args get_args = new rrdb.batch_get_args(request); + get_args.write(oprot); + oprot.writeMessageEnd(); + } + + @Override + public void recv_data(TProtocol iprot) throws TException { + rrdb.batch_get_result result = new rrdb.batch_get_result(); + result.read(iprot); + if (result.isSetSuccess()) { + response = result.success; + } else { + throw new org.apache.thrift.TApplicationException( + org.apache.thrift.TApplicationException.MISSING_RESULT, + "Batch Get failed: unknown result"); + } + } + + public batch_get_response get_response() { + return response; + } +} diff --git a/src/test/java/com/xiaomi/infra/pegasus/client/TestBatchGetByPartitions.java b/src/test/java/com/xiaomi/infra/pegasus/client/TestBatchGetByPartitions.java new file mode 100644 index 0000000000..a0af561ddb --- /dev/null +++ b/src/test/java/com/xiaomi/infra/pegasus/client/TestBatchGetByPartitions.java @@ -0,0 +1,122 @@ +// 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 com.xiaomi.infra.pegasus.client; + +import java.util.ArrayList; +import java.util.List; +import org.apache.commons.lang3.tuple.Pair; +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Test; + +public class TestBatchGetByPartitions { + volatile boolean isRunning = false; + static final int totalTestKeyNum = 101; + + @Test + public void testBatchGetByPartitions() throws PException { + String tableName = "temp"; + PegasusTableInterface table = PegasusClientFactory.getSingletonClient().openTable(tableName); + + List batchSetItems = new ArrayList<>(); + List> pairs = new ArrayList<>(); + List values = new ArrayList<>(); + for (int i = 0; i < totalTestKeyNum; ++i) { + SetItem oneItem = new SetItem(); + oneItem.hashKey = ("hashKey_" + i + "_" + System.currentTimeMillis()).getBytes(); + oneItem.sortKey = ("sortedKey_" + i + "_" + System.currentTimeMillis()).getBytes(); + oneItem.value = ("value_" + i + "_" + System.currentTimeMillis()).getBytes(); + pairs.add(Pair.of(oneItem.hashKey, oneItem.sortKey)); + values.add(oneItem.value); + batchSetItems.add(oneItem); + } + + List result = new ArrayList<>(); + table.batchSet2(batchSetItems, result, 0); + for (int i = 0; i < totalTestKeyNum; ++i) { + Assert.assertNull(result.get(i)); + } + + List> getResult = new ArrayList<>(); + int resultCount = table.batchGetByPartitions(pairs, getResult, 0); + Assert.assertEquals(totalTestKeyNum, resultCount); + + for (int i = 0; i < totalTestKeyNum; ++i) { + Assert.assertNull(getResult.get(i).getLeft()); + Assert.assertArrayEquals(getResult.get(i).getRight(), values.get(i)); + } + } + + @Test + public void testStableQpsForPegasusShellShow() throws Exception { + // only for auxiliary test + Assume.assumeTrue(false); + + String tableName = "temp"; + PegasusTableInterface table = PegasusClientFactory.getSingletonClient().openTable(tableName); + + List batchSetItems = new ArrayList<>(); + List> pairs = new ArrayList<>(); + List values = new ArrayList<>(); + for (int i = 0; i < totalTestKeyNum; ++i) { + SetItem oneItem = new SetItem(); + oneItem.hashKey = ("hashKey_" + i + "_" + System.currentTimeMillis()).getBytes(); + oneItem.sortKey = ("sortedKey_" + i + "_" + System.currentTimeMillis()).getBytes(); + oneItem.value = ("value_" + i + "_" + System.currentTimeMillis()).getBytes(); + pairs.add(Pair.of(oneItem.hashKey, oneItem.sortKey)); + values.add(oneItem.value); + batchSetItems.add(oneItem); + } + + List result = new ArrayList<>(); + table.batchSet2(batchSetItems, result, 0); + for (int i = 0; i < totalTestKeyNum; ++i) { + Assert.assertNull(result.get(i)); + } + + Runnable testRunnable = + new Runnable() { + @Override + public void run() { + while (isRunning) { + List> getResult = new ArrayList<>(); + try { + table.batchGetByPartitions(pairs, getResult, 0); + } catch (PException e) { + e.printStackTrace(); + } + + try { + Thread.sleep(50); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + }; + + isRunning = true; + Thread oneThread = new Thread(testRunnable); + oneThread.start(); + + Thread.sleep(600000); + + isRunning = false; + oneThread.join(); + } +}