@@ -121,27 +121,29 @@ Status RealtimeAppendOnlyWriter::Write(std::unique_ptr<RecordBatch>&& batch) {
121121Status RealtimeAppendOnlyWriter::SealCurrentSegment () {
122122 PAIMON_ASSIGN_OR_RAISE (std::optional<std::shared_ptr<RealtimeSegmentHandle>> segment,
123123 realtime_store_->SealForCommit ());
124- if (segment) {
125- if (!segment.value ()) {
126- return Status::Invalid (" append real-time store sealed a null segment" );
127- }
128- sealed_segments_.push_back (std::move (segment.value ()));
129- has_building_data_ = false ;
124+ std::lock_guard<std::mutex> lock (realtime_store_mutex_);
125+ if (!segment) {
126+ return Status::OK ();
130127 }
128+ if (!segment.value ()) {
129+ return Status::Invalid (" append real-time store sealed a null segment" );
130+ }
131+ has_building_data_ = next_offset_ > segment.value ()->GetOffsetRange ().end ;
132+ sealed_segments_.push_back (std::move (segment.value ()));
131133 return Status::OK ();
132134}
133135
134136Status RealtimeAppendOnlyWriter::Seal () {
135- std::lock_guard<std::mutex> lock (realtime_store_mutex_ );
137+ std::lock_guard<std::mutex> lock (prepare_mutex_ );
136138 return SealCurrentSegment ();
137139}
138140
139141Result<CommitIncrement> RealtimeAppendOnlyWriter::PrepareCommit (bool wait_compaction) {
140142 std::lock_guard<std::mutex> lock (prepare_mutex_);
143+ PAIMON_RETURN_NOT_OK (SealCurrentSegment ());
141144 std::vector<std::shared_ptr<RealtimeSegmentHandle>> segments;
142145 {
143146 std::lock_guard<std::mutex> realtime_store_lock (realtime_store_mutex_);
144- PAIMON_RETURN_NOT_OK (SealCurrentSegment ());
145147 segments.swap (sealed_segments_);
146148 }
147149 for (const std::shared_ptr<RealtimeSegmentHandle>& segment : segments) {
0 commit comments