public long handle(long uploadPeriodMS,
                       long maxRow,
                       SegmentUploader uploader,
                       RTResources rtResources) {
        Preconditions.checkState(state != State.Begin);

        if (isRecovering) {
            return recover(rtResources) ? fastPeriod : handlePeriod;
        }

        switch (state) {
            case Created: {
                if (!saveToDisk(rtResources)) {
                    return handlePeriod;
                }
                if (!allowAddSegment
                        || (timeToUpload(uploadPeriodMS, maxRow) && tryStartMerge())) {
                    // Check again, some new rts could be added into.
                    if (!saveToDisk(rtResources)) {
                        return handlePeriod;
                    }
                    return merge() ? fastPeriod : handlePeriod;
                } else {
                    return handlePeriod;
                }
            }
            case Merged: {
                if (!upload(uploader)) {
                    return handlePeriod;
                } else {
                    // Remove this rtsg later, wait for other nodes to load its segment.
                    return deleteDelayPeriod;
                }
            }
            case Uploaded: {
                return delete() ? -1 : handlePeriod;
            }
            default:
                throw new IllegalStateException("illegal state: " + state.name());
        }
    }
A thread may constantly call this method to finally push the segment into storage system.

@return -1: This rts group is done it's job, no more calls to handle; 0: should immediately call again; else: Next call period.
indexr-segment/src/main/java/io/indexr/segment/rt/RTSGroup.java