Skip to content

Commit 658ff42

Browse files
lgqssliguoqiang
and
liguoqiang
authored
fix bug count(distinct field) (#87)
* fix bug count(distinct field) * braft update to v1.1.1 * brpc update to 0.9.7 * fix bug mem row Co-authored-by: liguoqiang <liguoqiang@MacintoshdeMacBook-Pro.local>
1 parent dd6fef8 commit 658ff42

10 files changed

+84
-40
lines changed

WORKSPACE

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ bind(
137137
git_repository(
138138
name = "com_github_brpc_braft",
139139
remote = "https://github.com/baidu/braft.git",
140-
tag = "v1.0.2",
140+
tag = "v1.1.1",
141141
)
142142

143143
bind(
@@ -148,7 +148,7 @@ bind(
148148
git_repository(
149149
name = "com_github_brpc_brpc",
150150
remote= "https://github.com/apache/incubator-brpc.git",
151-
tag = "0.9.7-rc01",
151+
tag = "0.9.7",
152152
)
153153

154154
bind(

include/common/table_key.h

+2
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ using Reflection = google::protobuf::Reflection;
155155
const FieldInfo& field_info,
156156
int& pos) const;
157157

158+
int skip_field(const FieldInfo& field_info, int& pos) const;
159+
158160
private:
159161
bool _full; //full key or just a prefix
160162
rocksdb::Slice _data;

include/raft/my_raft_log_storage.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,7 @@ class MyRaftLogStorage : public braft::LogStorage {
9797

9898
// append entries to log, return append success number
9999
int append_entries(const std::vector<braft::LogEntry*>& entries
100-
#ifdef BAIDU_INTERNAL
101-
, braft::IOMetric* metric
102-
#endif
103-
) override;
100+
, braft::IOMetric* metric) override;
104101

105102
// delete logs from storage's head, [first_log_index, first_index_kept) will be discarded
106103
int truncate_prefix(const int64_t first_index_kept) override;

include/raft/my_raft_meta_storage.h

-5
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ class MyRaftMetaStorage : public RaftMetaStorage {
6666

6767
// set term and peer_id
6868
virtual int set_term_and_votedfor(const int64_t term, const braft::PeerId& peer_id);
69-
#ifdef BAIDU_INTERNAL
7069
// init stable storage
7170
virtual butil::Status init();
7271
// set term and votedfor information
@@ -75,10 +74,6 @@ class MyRaftMetaStorage : public RaftMetaStorage {
7574
// get term and votedfor information
7675
virtual butil::Status get_term_and_votedfor(int64_t* term, braft::PeerId* peer_id,
7776
const braft::VersionedGroupId& group);
78-
#else
79-
// init stable storage, check consistency and integrity
80-
virtual int init();
81-
#endif
8277

8378
RaftMetaStorage* new_instance(const std::string& uri) const override;
8479

src/common/table_key.cpp

+56
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,60 @@ int TableKey::decode_field(Message* message,
144144
return 0;
145145
}
146146

147+
//TODO: secondary key
148+
int TableKey::skip_field(const FieldInfo& field_info, int& pos) const {
149+
switch (field_info.type) {
150+
case pb::INT8: {
151+
pos += sizeof(int8_t);
152+
} break;
153+
case pb::INT16: {
154+
pos += sizeof(int16_t);
155+
} break;
156+
case pb::TIME:
157+
case pb::INT32: {
158+
pos += sizeof(int32_t);
159+
} break;
160+
case pb::INT64: {
161+
pos += sizeof(int64_t);
162+
} break;
163+
case pb::UINT8: {
164+
pos += sizeof(uint8_t);
165+
} break;
166+
case pb::UINT16: {
167+
pos += sizeof(uint16_t);
168+
} break;
169+
case pb::TIMESTAMP:
170+
case pb::DATE:
171+
case pb::UINT32: {
172+
pos += sizeof(uint32_t);
173+
} break;
174+
case pb::DATETIME:
175+
case pb::UINT64: {
176+
pos += sizeof(uint64_t);
177+
} break;
178+
case pb::FLOAT: {
179+
pos += sizeof(float);
180+
} break;
181+
case pb::DOUBLE: {
182+
pos += sizeof(double);
183+
} break;
184+
case pb::BOOL: {
185+
pos += sizeof(uint8_t);
186+
} break;
187+
case pb::STRING: {
188+
//TODO no string pk-field is supported
189+
if (pos >= (int)size()) {
190+
DB_WARNING("string pos out of bound: %d %zu", pos, size());
191+
return -2;
192+
}
193+
pos += (strlen(_data.data_) + 1);
194+
} break;
195+
default: {
196+
DB_WARNING("un-supported field type: %d", field_info.type);
197+
return -1;
198+
} break;
199+
}
200+
return 0;
201+
}
202+
147203
} // end of namespace baikaldb

src/common/tuple_record.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ inline const google::protobuf::FieldDescriptor* get_field(
2626
} else {
2727
int32_t slot = (*field_slot)[field_info->id];
2828
if (slot == 0) {
29+
DB_FATAL("field:%d, slot is 0, can't be here", field_info->id);
2930
return nullptr;
3031
}
3132
return (*mem_row)->get_field_by_slot(tuple_id, slot);

src/expr/agg_fn_call.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ struct AvgIntermediate {
173173
};
174174

175175
bool AggFnCall::is_initialize(MemRow* dst) {
176+
if (_is_distinct) {
177+
return false;
178+
}
179+
176180
if (dst->get_value(_tuple_id, _intermediate_slot_id).is_null()) {
177181
return true;
178182
}

src/mem_row/mem_row.cpp

+17-7
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,28 @@ int MemRow::decode_key(int32_t tuple_id, IndexInfo& index,
8080
pos += sizeof(uint8_t);
8181
}
8282
for (uint32_t idx = 0; idx < index.fields.size(); ++idx) {
83+
// DB_WARNING("null_flag: %ld, %u, %d, %d, %s",
84+
// index.id, null_flag, pos, index.fields[idx].can_null,
85+
// key.data().ToString(true).c_str());
86+
if (((null_flag >> (7 - idx)) & 0x01) && index.fields[idx].can_null) {
87+
//DB_DEBUG("field is null: %d", idx);
88+
continue;
89+
}
8390
int32_t slot = field_slot[index.fields[idx].id];
8491
//说明不需要解析
92+
//pos需要更新,容易出bug
8593
if (slot == 0) {
94+
if (0 != key.skip_field(index.fields[idx], pos)) {
95+
DB_WARNING("skip index field error");
96+
return -1;
97+
}
8698
continue;
8799
}
88100
const FieldDescriptor* field = descriptor->field(slot - 1);
89101
if (field == nullptr) {
90102
DB_WARNING("invalid field: %d slot: %d", index.fields[idx].id, slot);
91103
return -1;
92104
}
93-
// DB_WARNING("null_flag: %ld, %u, %d, %d, %s",
94-
// index.id, null_flag, pos, index.fields[idx].can_null,
95-
// key.data().ToString(true).c_str());
96-
if (((null_flag >> (7 - idx)) & 0x01) && index.fields[idx].can_null) {
97-
//DB_DEBUG("field is null: %d", idx);
98-
continue;
99-
}
100105
if (0 != key.decode_field(tuple, reflection, field, index.fields[idx], pos)) {
101106
DB_WARNING("decode index field error");
102107
return -1;
@@ -121,7 +126,12 @@ int MemRow::decode_primary_key(int32_t tuple_id, IndexInfo& index, std::vector<i
121126
for (uint32_t idx = 0; idx < index.pk_fields.size(); ++idx) {
122127
int32_t slot = field_slot[index.pk_fields[idx].id];
123128
//说明不需要解析
129+
//pos需要更新,容易出bug
124130
if (slot == 0) {
131+
if (0 != key.skip_field(index.fields[idx], pos)) {
132+
DB_WARNING("skip index field error");
133+
return -1;
134+
}
125135
continue;
126136
}
127137
const FieldDescriptor* field = descriptor->field(slot - 1);

src/raft/my_raft_log_storage.cpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -278,18 +278,11 @@ int64_t MyRaftLogStorage::get_term(const int64_t index) {
278278
int MyRaftLogStorage::append_entry(const braft::LogEntry* entry) {
279279
std::vector<braft::LogEntry*> entries;
280280
entries.push_back(const_cast<braft::LogEntry*>(entry));
281-
#ifdef BAIDU_INTERNAL
282281
return append_entries(entries, nullptr) == 1 ? 0 : -1;
283-
#else
284-
return append_entries(entries) == 1 ? 0 : -1;
285-
#endif
286282
}
287283

288284
int MyRaftLogStorage::append_entries(const std::vector<braft::LogEntry*>& entries
289-
#ifdef BAIDU_INTERNAL
290-
, braft::IOMetric* metric
291-
#endif
292-
) {
285+
, braft::IOMetric* metric) {
293286
TimeCost time_cost;
294287
if (entries.empty()) {
295288
return 0;

src/raft/my_raft_meta_storage.cpp

-14
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ int MyRaftMetaStorage::set_term_and_votedfor(const int64_t term, const braft::Pe
117117
}
118118
}
119119

120-
#ifdef BAIDU_INTERNAL
121120
butil::Status MyRaftMetaStorage::init() {
122121
butil::Status status;
123122
if (_is_inited) {
@@ -154,19 +153,6 @@ butil::Status MyRaftMetaStorage::get_term_and_votedfor(int64_t* term, braft::Pee
154153
status.set_error(EINVAL, "MyRaftMetaStorage is error, region_id: %ld", _region_id);
155154
return status;
156155
}
157-
#else
158-
int MyRaftMetaStorage::init() {
159-
if (_is_inited) {
160-
return 0;
161-
}
162-
163-
int ret = load();
164-
if (ret == 0) {
165-
_is_inited = true;
166-
}
167-
return ret;
168-
}
169-
#endif
170156

171157
int MyRaftMetaStorage::load() {
172158
braft::StablePBMeta meta;

0 commit comments

Comments
 (0)