Skip to content

Commit 3a295b2

Browse files
committed
fix examples dir path
1 parent def7593 commit 3a295b2

File tree

6 files changed

+49
-9
lines changed

6 files changed

+49
-9
lines changed

batch.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,23 @@ import (
1616
// An error will be returned if you try to use Put or Delete method.
1717
//
1818
// If readonly is false, you can use Put and Delete method to write data to the batch.
19-
// The data will be written to the database when you call Commit method.
19+
// The data will be written to the database permanently after you call Commit method.
20+
//
21+
// NB. There can only one write batch and multi read-only batches at the same time.
22+
// And the db method is not allowed to use before the batch commit/rollback.
23+
// So a typical usage of Batch is like:
24+
//
25+
// batch := db.NewBatch(rosedb.DefaultBatchOptions)
26+
// batch.Put/batch.Get (and other methods)
27+
// /* 1. a new write batch is not allowed */
28+
// /* 2. invoke DB method is not allowed, like db.Put */
29+
// batch.Commit() or batch.Rollback()
2030
//
2131
// Batch is not a transaction, it does not guarantee isolation.
2232
// But it can guarantee atomicity, consistency and durability(if the Sync options is true).
2333
//
24-
// You must call Commit method to commit the batch, otherwise the DB will be locked.
34+
// You must call Commit or Rollback method after using the batch,
35+
// otherwise the DB will be locked in an unexpected way.
2536
type Batch struct {
2637
db *DB
2738
pendingWrites []*LogRecord // save the data to be written
@@ -68,12 +79,11 @@ func newRecord() interface{} {
6879
return &LogRecord{}
6980
}
7081

71-
func (b *Batch) init(rdonly, sync bool, db *DB) *Batch {
82+
func (b *Batch) init(rdonly, sync bool, db *DB) {
7283
b.options.ReadOnly = rdonly
7384
b.options.Sync = sync
7485
b.db = db
7586
b.lock()
76-
return b
7787
}
7888

7989
func (b *Batch) reset() {

examples/batch/main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@ package main
22

33
import (
44
"github.com/rosedblabs/rosedb/v2"
5+
"runtime"
56
)
67

78
// this file shows how to use the batch operations of rosedb
89

910
func main() {
1011
// specify the options
1112
options := rosedb.DefaultOptions
12-
options.DirPath = "/tmp/rosedb_batch"
13+
sysType := runtime.GOOS
14+
if sysType == "windows" {
15+
options.DirPath = "C:\\rosedb_batch"
16+
} else {
17+
options.DirPath = "/tmp/rosedb_batch"
18+
}
1319

1420
// open a database
1521
db, err := rosedb.Open(options)

examples/iterate/main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"fmt"
5+
"runtime"
56

67
"github.com/rosedblabs/rosedb/v2"
78
)
@@ -11,7 +12,12 @@ import (
1112
func main() {
1213
// specify the options
1314
options := rosedb.DefaultOptions
14-
options.DirPath = "/tmp/rosedb_iterate"
15+
sysType := runtime.GOOS
16+
if sysType == "windows" {
17+
options.DirPath = "C:\\rosedb_iterate"
18+
} else {
19+
options.DirPath = "/tmp/rosedb_iterate"
20+
}
1521

1622
// open a database
1723
db, err := rosedb.Open(options)

examples/merge/main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"github.com/rosedblabs/rosedb/v2"
55
"github.com/rosedblabs/rosedb/v2/utils"
6+
"runtime"
67
)
78

89
// this file shows how to use the Merge feature of rosedb.
@@ -12,7 +13,12 @@ import (
1213
func main() {
1314
// specify the options
1415
options := rosedb.DefaultOptions
15-
options.DirPath = "/tmp/rosedb_merge"
16+
sysType := runtime.GOOS
17+
if sysType == "windows" {
18+
options.DirPath = "C:\\rosedb_merge"
19+
} else {
20+
options.DirPath = "/tmp/rosedb_merge"
21+
}
1622

1723
// open a database
1824
db, err := rosedb.Open(options)

examples/ttl/main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"log"
5+
"runtime"
56
"time"
67

78
"github.com/rosedblabs/rosedb/v2"
@@ -11,7 +12,12 @@ import (
1112
func main() {
1213
// specify the options
1314
options := rosedb.DefaultOptions
14-
options.DirPath = "/tmp/rosedb_ttl"
15+
sysType := runtime.GOOS
16+
if sysType == "windows" {
17+
options.DirPath = "C:\\rosedb_ttl"
18+
} else {
19+
options.DirPath = "/tmp/rosedb_ttl"
20+
}
1521

1622
// open a database
1723
db, err := rosedb.Open(options)

examples/watch/main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"fmt"
5+
"runtime"
56
"time"
67

78
"github.com/rosedblabs/rosedb/v2"
@@ -13,7 +14,12 @@ import (
1314
func main() {
1415
// specify the options
1516
options := rosedb.DefaultOptions
16-
options.DirPath = "/tmp/rosedb_watch"
17+
sysType := runtime.GOOS
18+
if sysType == "windows" {
19+
options.DirPath = "C:\\rosedb_watch"
20+
} else {
21+
options.DirPath = "/tmp/rosedb_watch"
22+
}
1723
options.WatchQueueSize = 1000
1824

1925
// open a database

0 commit comments

Comments
 (0)