You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ha...@apache.org on 2023/02/27 00:12:28 UTC

[skywalking-banyandb] branch main updated: Write-ahead Logging interface (#253)

This is an automated email from the ASF dual-hosted git repository.

hanahmily pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git


The following commit(s) were added to refs/heads/main by this push:
     new e0a1fd27 Write-ahead Logging interface (#253)
e0a1fd27 is described below

commit e0a1fd277b1c28efeee4dd932e354d7c524f83e6
Author: HHoflittlefish777 <77...@users.noreply.github.com>
AuthorDate: Mon Feb 27 08:12:23 2023 +0800

    Write-ahead Logging interface (#253)
    
    * Write-ahead Logging interface.
    
    ---------
    
    Co-authored-by: Jiajing LU <lu...@gmail.com>
    Co-authored-by: Gao Hongtao <ha...@gmail.com>
---
 api/common/id.go |  6 +++---
 pkg/wal/wal.go   | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 3 deletions(-)

diff --git a/api/common/id.go b/api/common/id.go
index 3a14c46e..b625028d 100644
--- a/api/common/id.go
+++ b/api/common/id.go
@@ -27,13 +27,13 @@ import (
 )
 
 type (
-	// SeriesID identity a series in a shard.
+	// SeriesID identities a series in a shard.
 	SeriesID uint64
 
-	// ShardID identity a shard in a tsdb.
+	// ShardID identities a shard in a tsdb.
 	ShardID uint32
 
-	// ItemID identity an item in a series.
+	// ItemID identities an item in a series.
 	ItemID uint64
 )
 
diff --git a/pkg/wal/wal.go b/pkg/wal/wal.go
new file mode 100644
index 00000000..bf325d0d
--- /dev/null
+++ b/pkg/wal/wal.go
@@ -0,0 +1,60 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+// Package wal (Write-ahead logging) is an independent component to ensure data reliability.
+package wal
+
+import (
+	"time"
+
+	"github.com/apache/skywalking-banyandb/api/common"
+)
+
+// SegmentID identities a segment in a WAL.
+type SegmentID uint64
+
+// Options for creating Write-ahead Logging.
+type Options struct{}
+
+// Segment allows reading underlying segments that hold WAl entities.
+type Segment interface {
+	GetSegmentID() SegmentID
+}
+
+// WAL denotes a Write-ahead logging.
+// Modules who want their data reliable could write data to an instance of WAL.
+// A WAL combines several segments, ingesting data on a single opened one.
+// Rotating the WAL will create a new segment, marking it as opened and persisting previous segments on the disk.
+type WAL interface {
+	// Write a logging entity.
+	// It will return immediately when the data is written in the buffer,
+	// The returned function will be called when the entity is flushed on the persistent storage.
+	Write(seriesID common.SeriesID, timestamp time.Time, data []byte) (func(), error)
+	// Read specified segment by SegmentID.
+	Read(segmentID SegmentID) (*Segment, error)
+	// ReadAllSegments reads all segments sorted by their creation time in ascending order.
+	ReadAllSegments() ([]*Segment, error)
+	// Rotate closes the open segment and opens a new one, returning the closed segment details.
+	Rotate() (*Segment, error)
+	// Delete the specified segment.
+	Delete(segmentID SegmentID) error
+}
+
+// New creates a WAL instance in the specified path.
+func New(_ string, _ Options) (WAL, error) {
+	return nil, nil
+}