A segment is a basic implementation of the segment related interfaces and represents a sequence of key-val entries or operations. A segment's kvs will be sorted by key when the segment is pushed into the collection. A segment implements the Batch interface.
| 98 | // is pushed into the collection. A segment implements the Batch |
| 99 | // interface. |
| 100 | type segment struct { |
| 101 | // Each key-val operation is encoded as 2 uint64's... |
| 102 | // - operation (see: maskOperation) | |
| 103 | // key length (see: maskKeyLength) | |
| 104 | // val length (see: maskValLength). |
| 105 | // - start index into buf for key-val bytes. |
| 106 | kvs []uint64 |
| 107 | |
| 108 | // Contiguous backing memory for the keys and vals of the segment. |
| 109 | buf []byte |
| 110 | |
| 111 | // If this segment needs sorting, then needSorterCh will be |
| 112 | // non-nil and also the first goroutine that reads successfully |
| 113 | // from needSorterCh becomes the sorter of this segment. All |
| 114 | // other goroutines must instead wait on the waitSortedCh. |
| 115 | needSorterCh chan bool |
| 116 | |
| 117 | // Once the sorter of this segment is done sorting the kvs, it |
| 118 | // close()'s the waitSortedCh, treating waitSortedCh like a |
| 119 | // one-way latch. The needSorterCh and waitSortedCh will either |
| 120 | // be nil or non-nil together. A segment that was "born |
| 121 | // sorted" will have needSorterCh and waitSortedCh as both nil. |
| 122 | waitSortedCh chan struct{} |
| 123 | |
| 124 | totOperationSet uint64 |
| 125 | totOperationDel uint64 |
| 126 | totOperationMerge uint64 |
| 127 | totKeyByte uint64 |
| 128 | totValByte uint64 |
| 129 | |
| 130 | rootCollection *collection // Non-nil when segment is from a batch. |
| 131 | |
| 132 | // In-memory index, immutable after segment initialization. |
| 133 | index *segmentKeysIndex |
| 134 | } |
| 135 | |
| 136 | // See the OperationXxx consts. |
| 137 | const maskOperation = uint64(0x0F00000000000000) |
nothing calls this directly
no outgoing calls
no test coverage detected