bool StoreListener::getAttachmentData(const idgs::actor::ActorMessagePtr& msg, idgs::actor::PbMessagePtr& key, idgs::actor::PbMessagePtr& value) { protobuf::MessageHelper& helper = idgs::util::singleton<protobuf::MessageHelper>::getInstance(); const string& keyType = storeConfig->getStoreConfig().key_type(); key = msg->getAttachement(STORE_ATTACH_KEY); if (!key) { key = helper.createMessage(keyType); if (!key) { LOG(ERROR) << "key type " << keyType << " is not registered."; return false; } if (!msg->parseAttachment(STORE_ATTACH_KEY, key.get())) { LOG(ERROR) << "invalid key with type " << keyType; return false; } } const string& valueType = storeConfig->getStoreConfig().value_type(); value = msg->getAttachement(STORE_ATTACH_VALUE); if (!value) { value = helper.createMessage(valueType); if (!key) { LOG(ERROR) << "value type " << valueType << " is not registered."; return false; } if (!msg->parseAttachment(STORE_ATTACH_VALUE, value.get())) { LOG(ERROR) << "invalid value with type " << valueType; return false; } } return true; }
void BaseRddPartition::transform(const idgs::actor::PbMessagePtr& key, const idgs::actor::PbMessagePtr& value) { if (!key.get()) { LOG(ERROR)<< getPartitionName() << " transform data, key is null"; return; } if(!value) { LOG(ERROR)<< getPartitionName() << " transform data, value is null"; return; } auto& downstreamPartition = rddLocal->getDownstreamPartition(partition); if (!downstreamPartition.empty()) { idgs::rdd::pb::RddResultCode code = idgs::rdd::pb::RRC_SUCCESS; for (int32_t i = 0; i < downstreamPartition.size(); ++ i) { auto& rddlocal = downstreamPartition[i]->getRddLocal(); auto& ctx = transformerContexts.at(i); idgs::actor::PbMessagePtr outkey, outvalue; ctx.getExpressionContext()->setKeyValue(&key, &value); ctx.getExpressionContext()->setOutputKeyValue(&outkey, &outvalue); if (!rddlocal->isUpstreamSync()) { auto upstreamPartition = rddlocal->getUpstreamPartition(partition); if (upstreamPartition[0] == this) { if (ctx.getParamRdds().empty()) { std::vector<BaseRddPartition*> params; for (int32_t i = 1; i < upstreamPartition.size(); ++ i) { params.push_back(upstreamPartition[i]); } ctx.setParamRdds(params); } } else { continue; } } code = rddlocal->getTransformer()->transform(&ctx, downstreamPartition[i]); if (code != idgs::rdd::pb::RRC_SUCCESS) { LOG(ERROR) << getPartitionName() << " transform error, caused by " << idgs::rdd::pb::RddResultCode_Name(code); } } } }