lotusdblabs / lotusdb

Most advanced key-value database written in Go, extremely fast, compatible with LSM tree and B+ tree.
https://lotusdblabs.github.io
Apache License 2.0
2.09k stars 184 forks source link

WriteOption uses value variables and there is no need to escape to the heap #120

Closed shaovie closed 11 months ago

shaovie commented 1 year ago

抱歉,把options.go的修改了一把提交了 我觉得弄几个语义变量,比每次都自己构造 WriteOption要优雅多了 ^_^

akiozihao commented 1 year ago

Is it better to implement it using Functional Options? Like

type Option func(option *WriteOptions)

func WithSync() Option {
    return func(option *WriteOptions) {
        option.Sync = true
    }
}

func WithDisableWal() Option {
    return func(option *WriteOptions) {
        option.DisableWal = true
    }
}

func NewWriteOptions(options ...Option) WriteOptions {
    var option WriteOptions
    for _, opt := range options {
        opt(&option)
    }
    return option
}
shaovie commented 1 year ago

This mode is more complex to use. It is not a configuration option, but a frequently used input parameter. I think there are two ways to choose from

  1. Use default defined option variables with semantics
  2. Use semantic method names, such as PutReliable (k, v), which is the recommended method for @roseduan
roseduan commented 1 year ago

你好,能拆分一下吗,这个改动太多了不太好 review。 可以尽量拆成单一职责的 PR。

shaovie commented 1 year ago

你好,能拆分一下吗,这个改动太多了不太好 review。 可以尽量拆成单一职责的 PR。

抱歉,这个怎么拆?我这边怎样操作?

roseduan commented 1 year ago

你好,能拆分一下吗,这个改动太多了不太好 review。 可以尽量拆成单一职责的 PR。

抱歉,这个怎么拆?我这边怎样操作?

就是提多个 PR,每个 PR 只做一件事情的修改