You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by "hailin0 (via GitHub)" <gi...@apache.org> on 2023/06/25 05:55:52 UTC

[GitHub] [skywalking-banyandb] hailin0 commented on a diff in pull request #261: Implement Write-ahead Logging

hailin0 commented on code in PR #261:
URL: https://github.com/apache/skywalking-banyandb/pull/261#discussion_r1241045251


##########
pkg/wal/wal.go:
##########
@@ -153,147 +157,258 @@ func New(path string, options *Options) (WAL, error) {
 	if options.BufferSize <= 0 {
 		options.BufferSize = DefaultOptions.BufferSize
 	}
+	if options.BufferBatchInterval <= 0 {
+		options.BufferBatchInterval = DefaultOptions.BufferBatchInterval
+	}
 
 	// Initial WAL path.
 	path, err := filepath.Abs(path)
 	if err != nil {
-		return nil, errors.Wrap(err, "Can not get absolute path")
+		return nil, errors.Wrap(err, "Can not get absolute path: "+path)
 	}
-	log := &Log{path: path, options: *options}
 	if err := os.MkdirAll(path, os.ModePerm); err != nil {
 		return nil, err
 	}
 
+	log := &Log{path: path, options: *options, logger: logger.GetLogger(moduleName)}
+
 	if err := log.load(); err != nil {
 		return nil, err
 	}
-	log.runFlushTask()
+	log.startAsyncFlushTask()
+
+	log.logger.Info().Msgf("WAL initialized at %s", path)
 	return log, nil
 }
 
-func (log *Log) runFlushTask() {
+// Write a logging entity.
+// It will return immediately when the data is written in the buffer,
+// The callback function will be called when the entity is flushed on the persistent storage.
+func (log *Log) Write(seriesID common.SeriesIDV2, timestamp time.Time, data []byte,
+	callback func(common.SeriesIDV2, time.Time, []byte, error)) {
+	log.writeChannel <- logRequest{
+		seriesID:  seriesID,
+		timestamp: timestamp,
+		data:      data,
+		callback:  callback,
+	}
+}
+
+// Read specified segment by SegmentID.
+func (log *Log) Read(segmentID SegmentID) (Segment, error) {
+	segment := log.segmentIndexMap[segmentID]
+	return segment, nil
+}
+
+// ReadAllSegments reads all segments sorted by their creation time in ascending order.
+func (log *Log) ReadAllSegments() ([]Segment, error) {
+	segments := make([]Segment, 0)
+	for _, segment := range log.segmentIndexMap {
+		segments = append(segments, segment)
+	}
+	return segments, nil
+}
+
+// Rotate closes the open segment and opens a new one, returning the closed segment details.
+func (log *Log) Rotate() (Segment, error) {
+	// 需要锁定

Review Comment:
   thanks, in this commit fixed
   
   <img width="930" alt="image" src="https://github.com/apache/skywalking-banyandb/assets/14371345/f427c9d3-a958-4162-90d5-dd360bdf267c">
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org