Result AdminRequestChecker::checkTopicCreationRequest()

in aios/apps/facility/swift/admin/AdminRequestChecker.cpp [58:149]


Result<bool> AdminRequestChecker::checkTopicCreationRequest(const TopicCreationRequest *request,
                                                            config::AdminConfig *config,
                                                            bool checkPartCnt) {
    bool hasDfsRoot = !config->getDfsRoot().empty();
    // Check topic name
    if (!request->has_topicname() || !ParaChecker::checkValidTopicName(request->topicname())) {
        AUTIL_LOG(ERROR, "Invalid topic name [%s]", request->ShortDebugString().c_str());
        return RuntimeError::make("Invalid topic name");
    }
    if (checkPartCnt) {
        if (!request->has_partitioncount()) {
            AUTIL_LOG(ERROR, "Invalid topic partition, request [%s]", request->ShortDebugString().c_str());
            return RuntimeError::make("Topic partition not assigned");
        }
    }
    if (request->has_partitioncount()) {
        // Check partition count
        if (request->partitioncount() <= MIN_PARTITION_COUNT || request->partitioncount() > MAX_PARTITION_COUNT) {
            AUTIL_LOG(ERROR, "Partition count is invalid [%s]", request->ShortDebugString().c_str());
            return RuntimeError::make("Partition count is invalid[%d]", request->partitioncount());
        }
    }
    // Check partition buffer size
    if (request->has_partitionbuffersize()) {
        if (request->partitionbuffersize() <= MIN_PARTITION_BUFFER_SIZE ||
            request->partitionbuffersize() > MAX_PARTITION_BUFFER_SIZE) {
            AUTIL_LOG(ERROR, "Partition buffer size is invalid [%s]", request->ShortDebugString().c_str());
            return RuntimeError::make("Partition buffer size is invalid[%d]", request->partitionbuffersize());
        }
    } else if (request->partitionminbuffersize() <= MIN_PARTITION_BUFFER_SIZE ||
               request->partitionminbuffersize() > MAX_PARTITION_BUFFER_SIZE ||
               request->partitionmaxbuffersize() > MAX_PARTITION_BUFFER_SIZE ||
               request->partitionmaxbuffersize() < request->partitionminbuffersize()) {
        AUTIL_LOG(ERROR, "Partition buffer size is invalid [%s]", request->ShortDebugString().c_str());
        return RuntimeError::make("Partition buffer size is invalid min[%d] max[%d]",
                                  request->partitionminbuffersize(),
                                  request->partitionmaxbuffersize());
    }
    // Check resource
    if (request->resource() <= MIN_RESOURCE || request->resource() > MAX_RESOURCE) {
        AUTIL_LOG(ERROR, "Resource is invalid [%d]", request->resource());
        return RuntimeError::make("Resource is invalid[%d]", request->resource());
    }
    // Check partition limit
    if (request->partitionlimit() < MIN_PARTITION_LIMIT) {
        AUTIL_LOG(ERROR, "partition limit is invalid [%u]", request->partitionlimit());
        return RuntimeError::make("Partition limit is invalid[%d]", request->partitionlimit());
    }
    // check topic mode
    if (TOPIC_MODE_SECURITY == request->topicmode()) {
        if (!hasDfsRoot) {
            AUTIL_LOG(ERROR, "dataDir should not be empty, when topic mode is TOPIC_MODE_SECURITY");
            return RuntimeError::make("Dfsroot not assigned when topic mode is TOPIC_MODE_SECURITY");
        }
        if (request->maxwaittimeforsecuritycommit() < 0 || request->maxdatasizeforsecuritycommit() < 0) {
            AUTIL_LOG(ERROR, "maxWaitTime or maxDataSize should not less than zero");
            return RuntimeError::make("Invalid maxWaitTime[%ld] or maxDataSize[%ld]",
                                      request->maxwaittimeforsecuritycommit(),
                                      request->maxdatasizeforsecuritycommit());
        }
    }
    // check obsoleteFileTimeInterval
    int64_t timeInterval = request->obsoletefiletimeinterval();
    if (timeInterval != TopicCreationRequest::default_instance().obsoletefiletimeinterval() &&
        timeInterval < MIN_OBSOLETE_FILE_TIME_INTERVAL) {
        AUTIL_LOG(ERROR, "obsoleteFileTimeInterval is invalid [%ld].", timeInterval);
        return RuntimeError::make("Invalid obsoleteFileTimeInterval[%ld]", timeInterval);
    }
    // check reservedFileCount
    int32_t fileCount = request->reservedfilecount();
    if (fileCount != TopicCreationRequest::default_instance().reservedfilecount() &&
        fileCount < MIN_RESERVED_FILE_COUNT) {
        AUTIL_LOG(ERROR, "reservedFileCount is invalid [%d].", fileCount);
        return RuntimeError::make("Invalid reservedFileCount[%d]", fileCount);
    }
    if (request->has_needfieldfilter() && request->has_needschema()) {
        if (request->needfieldfilter() && request->needschema()) {
            AUTIL_LOG(ERROR, "needfieldfilter and needschema should set 1 only");
            return RuntimeError::make("needfieldfilter and needschema should set 1 only");
        }
    }
    if (request->topictype() == TOPIC_TYPE_PHYSIC && !LogicTopicHelper::isValidPhysicTopicName(request->topicname())) {
        AUTIL_LOG(ERROR, "can not create physic topic[%s]", request->topicname().c_str());
        return RuntimeError::make("can not create physic topic[%s]", request->topicname().c_str());
    }
    // check rangeCountInPartition
    if (request->has_rangecountinpartition() && 1 != request->rangecountinpartition()) {
        AUTIL_LOG(ERROR, "rangeCountInPartition[%d] invalid, must be 1", request->rangecountinpartition());
        return RuntimeError::make("rangeCountInPartition[%d] invalid, must be 1", request->rangecountinpartition());
    }
    return true;
}