@@ -139,8 +139,28 @@ type Writer interface {
139
139
// properly. Only use if you have a workload where the performance gain is critical and you
140
140
// can guarantee that a record is written once and then deleted once.
141
141
//
142
- // SingleDelete is internally transformed into a Delete if the most recent record for a key is either
143
- // a Merge or Delete record.
142
+ // Note that SINGLEDEL, SET, SINGLEDEL, SET, DEL/RANGEDEL, ... from most
143
+ // recent to older will work as intended since there is a single SET
144
+ // sandwiched between SINGLEDEL/DEL/RANGEDEL.
145
+ //
146
+ // IMPLEMENTATION WARNING: By offering SingleDelete, Pebble must guarantee
147
+ // that there is no duplication of writes inside Pebble. That is, idempotent
148
+ // application of writes is insufficient. For example, if a SET operation
149
+ // gets duplicated inside Pebble, resulting in say SET#20 and SET#17, the
150
+ // caller may issue a SINGLEDEL#25 and it will not have the desired effect.
151
+ // A duplication where a SET#20 is duplicated across two sstables will have
152
+ // the same correctness problem, since the SINGLEDEL may meet one of the
153
+ // SETs. This guarantee is partially achieved by ensuring that a WAL and a
154
+ // flushable are usually in one-to-one correspondence, and atomically
155
+ // updating the MANIFEST when the flushable is flushed (which ensures the
156
+ // WAL will never be replayed). There is one exception: a flushableBatch (a
157
+ // batch too large to fit in a memtable) is written to the end of the WAL
158
+ // that it shares with the preceding memtable. This is safe because the
159
+ // memtable and the flushableBatch are part of the same flush (see DB.flush1
160
+ // where this invariant is maintained). If the memtable were to be flushed
161
+ // without the flushableBatch, the WAL cannot yet be deleted and if a crash
162
+ // happened, the WAL would be replayed despite the memtable already being
163
+ // flushed.
144
164
//
145
165
// It is safe to modify the contents of the arguments after SingleDelete returns.
146
166
SingleDelete (key []byte , o * WriteOptions ) error
@@ -682,6 +702,8 @@ func (d *DB) DeleteSized(key []byte, valueSize uint32, opts *WriteOptions) error
682
702
// SingleDelete adds an action to the batch that single deletes the entry for key.
683
703
// See Writer.SingleDelete for more details on the semantics of SingleDelete.
684
704
//
705
+ // WARNING: See the detailed warning in Writer.SingleDelete before using this.
706
+ //
685
707
// It is safe to modify the contents of the arguments after SingleDelete returns.
686
708
func (d * DB ) SingleDelete (key []byte , opts * WriteOptions ) error {
687
709
b := newBatch (d )
0 commit comments