Skip to content

Commit

Permalink
address dangleptr's comment
Browse files Browse the repository at this point in the history
  • Loading branch information
panda-sheep committed Mar 19, 2020
1 parent 52a3756 commit 54f1ed4
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 36 deletions.
3 changes: 2 additions & 1 deletion src/storage/query/QueryBaseProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ class QueryBaseProcessor : public BaseProcessor<RESP> {

bool checkExp(const Expression* exp);

void buildTagTTLInfo(TagID tagId);
// Only use in fetch prop on * vertexID
folly::Optional<std::pair<std::string, int64_t>> tagTTLInfo(TagID tagId);

void buildTTLInfoAndRespSchema();

Expand Down
104 changes: 72 additions & 32 deletions src/storage/query/QueryBaseProcessor.inl
Original file line number Diff line number Diff line change
Expand Up @@ -674,43 +674,49 @@ std::vector<Bucket> QueryBaseProcessor<REQ, RESP>::genBuckets(
}

template<typename REQ, typename RESP>
void QueryBaseProcessor<REQ, RESP>::buildTagTTLInfo(TagID tagId) {
folly::Optional<std::pair<std::string, int64_t>>
QueryBaseProcessor<REQ, RESP>::tagTTLInfo(TagID tagId) {
folly::Optional<std::pair<std::string, int64_t>> ret;
auto tagFound = tagTTLInfo_.find(tagId);
if (tagFound != tagTTLInfo_.end()) {
return;
}
if (tagFound == tagTTLInfo_.end()) {
// Build tag ttl info
auto tagschema = this->schemaMan_->getTagSchema(spaceId_, tagId);
if (!tagschema) {
VLOG(3) << "Can't find spaceId " << spaceId_ << ", tagId " << tagId;
return ret;
}

auto tagschema = this->schemaMan_->getTagSchema(spaceId_, tagId);
if (!tagschema) {
VLOG(3) << "Can't find spaceId " << spaceId_ << ", tagId " << tagId;
return;
}
const meta::NebulaSchemaProvider* nschema =
dynamic_cast<const meta::NebulaSchemaProvider*>(tagschema.get());
if (nschema == NULL) {
VLOG(3) << "Can't find NebulaSchemaProvider in spaceId " << spaceId_;
return;
}
const meta::NebulaSchemaProvider* nschema =
dynamic_cast<const meta::NebulaSchemaProvider*>(tagschema.get());
if (nschema == NULL) {
VLOG(3) << "Can't find NebulaSchemaProvider in spaceId " << spaceId_;
return ret;
}

const nebula::cpp2::SchemaProp schemaProp = nschema->getProp();
const nebula::cpp2::SchemaProp schemaProp = nschema->getProp();

int64_t ttlDuration = 0;
if (schemaProp.get_ttl_duration()) {
ttlDuration = *schemaProp.get_ttl_duration();
}
std::string ttlCol;
if (schemaProp.get_ttl_col()) {
ttlCol = *schemaProp.get_ttl_col();
}
int64_t ttlDuration = 0;
if (schemaProp.get_ttl_duration()) {
ttlDuration = *schemaProp.get_ttl_duration();
}
std::string ttlCol;
if (schemaProp.get_ttl_col()) {
ttlCol = *schemaProp.get_ttl_col();
}

// Only support the specified ttl_col mode
// Not specifying or non-positive ttl_duration behaves like ttl_duration = infinity
if (ttlCol.empty() || ttlDuration <= 0) {
VLOG(3) << "TTL property is invalid";
return;
}
// Only support the specified ttl_col mode
// Not specifying or non-positive ttl_duration behaves like ttl_duration = infinity
if (ttlCol.empty() || ttlDuration <= 0) {
VLOG(3) << "TTL property is invalid";
return ret;
}

tagTTLInfo_.emplace(tagId, std::make_pair(ttlCol, ttlDuration));
tagTTLInfo_.emplace(tagId, std::make_pair(ttlCol, ttlDuration));
ret.emplace(ttlCol, ttlDuration);
} else {
ret.emplace(tagFound->second.first, tagFound->second.second);
}
return ret;
}

template<typename REQ, typename RESP>
Expand All @@ -737,7 +743,41 @@ void QueryBaseProcessor<REQ, RESP>::buildTTLInfoAndRespSchema() {
}

// build ttl info
buildTagTTLInfo(tc.tagId_);
auto tagFound = tagTTLInfo_.find(tc.tagId_);
if (tagFound != tagTTLInfo_.end()) {
continue;
}

auto tagschema = this->schemaMan_->getTagSchema(spaceId_, tc.tagId_);
if (!tagschema) {
VLOG(3) << "Can't find spaceId " << spaceId_ << ", tagId " << tc.tagId_;
continue;
}
const meta::NebulaSchemaProvider* nschema =
dynamic_cast<const meta::NebulaSchemaProvider*>(tagschema.get());
if (nschema == NULL) {
VLOG(3) << "Can't find NebulaSchemaProvider in spaceId " << spaceId_;
continue;
}

const nebula::cpp2::SchemaProp schemaProp = nschema->getProp();
nt64_t ttlDuration = 0;
if (schemaProp.get_ttl_duration()) {
ttlDuration = *schemaProp.get_ttl_duration();
}
std::string ttlCol;
if (schemaProp.get_ttl_col()) {
ttlCol = *schemaProp.get_ttl_col();
}

// Only support the specified ttl_col mode
// Not specifying or non-positive ttl_duration behaves like ttl_duration = infinity
if (ttlCol.empty() || ttlDuration <= 0) {
LOG(3) << "TTL property is invalid";
continue;
}

tagTTLInfo_.emplace(tc.tagId_, std::make_pair(ttlCol, ttlDuration));
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/storage/query/QueryVertexPropsProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ kvstore::ResultCode QueryVertexPropsProcessor::collectVertexProps(
// Already found the latest version.
continue;
}
// Build TTL info
buildTagTTLInfo(tagId);

VLOG(3) << "Found tag " << tagId << " for vId" << vId;

Expand All @@ -101,7 +99,7 @@ kvstore::ResultCode QueryVertexPropsProcessor::collectVertexProps(
}
auto reader = RowReader::getTagPropReader(this->schemaMan_, val, spaceId_, tagId);
// Check if ttl data expired
auto retTTL = getTagTTLInfo(tagId);
auto retTTL = tagTTLInfo(tagId);
if (retTTL.has_value() && checkDataExpiredForTTL(schema.get(),
reader.get(),
retTTL.value().first,
Expand Down

0 comments on commit 54f1ed4

Please sign in to comment.