MCPcopy Index your code
hub / github.com/perkeep/perkeep / CommitBatch

Method CommitBatch

pkg/sorted/kvfile/kvfile.go:140–176  ·  view source on GitHub ↗
(bm sorted.BatchMutation)

Source from the content-addressed store, hash-verified

138}
139
140func (is *kvis) CommitBatch(bm sorted.BatchMutation) error {
141 b, ok := bm.(batch)
142 if !ok {
143 return errors.New("invalid batch type")
144 }
145 is.txmu.Lock()
146 defer is.txmu.Unlock()
147
148 good := false
149 defer func() {
150 if !good {
151 is.db.Rollback()
152 }
153 }()
154
155 if err := is.db.BeginTransaction(); err != nil {
156 return err
157 }
158 for _, m := range b.Mutations() {
159 if m.IsDelete() {
160 if err := is.db.Delete([]byte(m.Key())); err != nil {
161 return err
162 }
163 } else {
164 if err := sorted.CheckSizes(m.Key(), m.Value()); err != nil {
165 log.Printf("Skipping storing (%q:%q): %v", m.Key(), m.Value(), err)
166 continue
167 }
168 if err := is.db.Set([]byte(m.Key()), []byte(m.Value())); err != nil {
169 return err
170 }
171 }
172 }
173
174 good = true
175 return is.db.Commit()
176}
177
178func (is *kvis) Close() error {
179 log.Printf("Closing kvfile database %s", is.path)

Callers

nothing calls this directly

Calls 10

CheckSizesFunction · 0.92
LockMethod · 0.80
UnlockMethod · 0.80
PrintfMethod · 0.80
MutationsMethod · 0.65
IsDeleteMethod · 0.65
DeleteMethod · 0.65
KeyMethod · 0.65
ValueMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected