Show HN: WAL Implementation in Golang
github.com
Show HN: WAL Implementation in Golang
1–10 of 30 posts
Re: Show HN: WAL Implementation in Golang
#2Since you mention etcd/wal:
https://github.com/etcd-io/etcd/blob/v3.3.27/wal/wal.go#L671
https://github.com/etcd-io/etcd/blob/v3.3.27/pkg/fileutil/sy...
Re: Show HN: WAL Implementation in Golang
#3Did I miss it or is there no call to os.File.Sync(), i.e. fsync, anywhere? Since you mention etcd/wal: https://github.com/etcd-io/etcd/blob/v3.3.27/wal/wal.go#L671 https://github.com/etcd-io/etcd/blob/v3.3.27/pkg/fileutil/sy...
Thanks for your comment, I'll definitely check it out. It was my first attempt at this. How can I make it better?
Re: Show HN: WAL Implementation in Golang
#4Did I miss it or is there no call to os.File.Sync(), i.e. fsync, anywhere? Since you mention etcd/wal: https://github.com/etcd-io/etcd/blob/v3.3.27/wal/wal.go#L671 https://github.com/etcd-io/etcd/blob/v3.3.27/pkg/fileutil/sy...
I used the bufio flush mechanism https://pkg.go.dev/bufio#Writer.Flush Thanks for your comment, I'll definitely check it out. It was my first attempt at this. How can I make it better?
Re: Show HN: WAL Implementation in Golang
#5I also think your rotation will delete the wrong segment when you have more than ten segments - imagine you're writing rebuf-1 to rebuf-10 - what's the "oldest file" to delete now? Besides, should you really delete those files?
Re: Show HN: WAL Implementation in Golang
#6Besides what Phil mentioned below, I can't write more than one record to the WAL. You're closing the file after every write, the second time you write the error `seek data/rebuf.tmp: file already closed` is returned. I also think your rotation will delete the wrong segment when you have more than ten segments - imagine you're writing rebuf-1 to rebuf-10 - what's the "oldest file" to delete now? Besides, should you re…
Re: Show HN: WAL Implementation in Golang
#7Earlier quoted context omitted.
I used the bufio flush mechanism https://pkg.go.dev/bufio#Writer.Flush Thanks for your comment, I'll definitely check it out. It was my first attempt at this. How can I make it better?
Essentially, unless you `fsync`, there's no guarantee that your data will be durably written to disk. This is because the operating system keeps data buffered in in-memory caches, so if the machine crashes you may lose some data. The `fsync` system call forces the data to be flushed from the in-memory OS cache to the disk. As far as I could tell, the Flush you use does not `fsync`.
Re: Show HN: WAL Implementation in Golang
#81. Use fsync for durable writes in case of system crashes
2. Fix log-rotation-purging logic
3. Fix `file already closed` bug on consecutive writes
4. Add CRC checksum
Re: Show HN: WAL Implementation in Golang
#9Similar to RocksDB.
Re: Show HN: WAL Implementation in Golang
#10Besides what Phil mentioned below, I can't write more than one record to the WAL. You're closing the file after every write, the second time you write the error `seek data/rebuf.tmp: file already closed` is returned. I also think your rotation will delete the wrong segment when you have more than ten segments - imagine you're writing rebuf-1 to rebuf-10 - what's the "oldest file" to delete now? Besides, should you re…
Yes there are a lot of bugs since I just wrote this in one sitting today. Will be fixing all of this. For log rotation, I'll sort by the last_modified_at ts and then purge those