| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package memory | 5 package memory |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "fmt" | 9 "fmt" |
| 10 "sync" | 10 "sync" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 } else { | 100 } else { |
| 101 idKey = groupIDsKey(key) | 101 idKey = groupIDsKey(key) |
| 102 } | 102 } |
| 103 id := incrementLocked(ents, idKey) | 103 id := incrementLocked(ents, idKey) |
| 104 key = ds.NewKey(key.AppID(), key.Namespace(), key.Kind(), "", id
, key.Parent()) | 104 key = ds.NewKey(key.AppID(), key.Namespace(), key.Kind(), "", id
, key.Parent()) |
| 105 } | 105 } |
| 106 | 106 |
| 107 return ents, key | 107 return ents, key |
| 108 } | 108 } |
| 109 | 109 |
| 110 func (d *dataStoreData) putMulti(keys []ds.Key, vals []ds.PropertyLoadSaver, cb
ds.PutMultiCB) { | 110 func (d *dataStoreData) putMulti(keys []ds.Key, vals []ds.PropertyMap, cb ds.Put
MultiCB) { |
| 111 for i, k := range keys { | 111 for i, k := range keys { |
| 112 buf := &bytes.Buffer{} | 112 buf := &bytes.Buffer{} |
| 113 » » pmap := vals[i].(ds.PropertyMap) | 113 » » pmap, _ := vals[i].Save(false) |
| 114 pmap.Write(buf, ds.WithoutContext) | 114 pmap.Write(buf, ds.WithoutContext) |
| 115 dataBytes := buf.Bytes() | 115 dataBytes := buf.Bytes() |
| 116 | 116 |
| 117 k, err := func() (ret ds.Key, err error) { | 117 k, err := func() (ret ds.Key, err error) { |
| 118 d.rwlock.Lock() | 118 d.rwlock.Lock() |
| 119 defer d.rwlock.Unlock() | 119 defer d.rwlock.Unlock() |
| 120 | 120 |
| 121 ents, ret := d.entsKeyLocked(k) | 121 ents, ret := d.entsKeyLocked(k) |
| 122 incrementLocked(ents, groupMetaKey(ret)) | 122 incrementLocked(ents, groupMetaKey(ret)) |
| 123 | 123 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 continue | 239 continue |
| 240 } | 240 } |
| 241 // TODO(riannucci): refactor to do just 1 putMulti, and 1 delMul
ti | 241 // TODO(riannucci): refactor to do just 1 putMulti, and 1 delMul
ti |
| 242 for _, m := range muts { | 242 for _, m := range muts { |
| 243 err := error(nil) | 243 err := error(nil) |
| 244 k := m.key | 244 k := m.key |
| 245 if m.data == nil { | 245 if m.data == nil { |
| 246 d.delMulti([]ds.Key{k}, | 246 d.delMulti([]ds.Key{k}, |
| 247 func(e error) { err = e }) | 247 func(e error) { err = e }) |
| 248 } else { | 248 } else { |
| 249 » » » » d.putMulti([]ds.Key{m.key}, []ds.PropertyLoadSav
er{m.data}, | 249 » » » » d.putMulti([]ds.Key{m.key}, []ds.PropertyMap{m.d
ata}, |
| 250 func(_ ds.Key, e error) { err = e }) | 250 func(_ ds.Key, e error) { err = e }) |
| 251 } | 251 } |
| 252 err = errors.SingleError(err) | 252 err = errors.SingleError(err) |
| 253 if err != nil { | 253 if err != nil { |
| 254 panic(err) | 254 panic(err) |
| 255 } | 255 } |
| 256 } | 256 } |
| 257 } | 257 } |
| 258 } | 258 } |
| 259 | 259 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 } | 352 } |
| 353 td.muts[rk] = []txnMutation{} | 353 td.muts[rk] = []txnMutation{} |
| 354 } | 354 } |
| 355 if !getOnly { | 355 if !getOnly { |
| 356 td.muts[rk] = append(td.muts[rk], txnMutation{key, data}) | 356 td.muts[rk] = append(td.muts[rk], txnMutation{key, data}) |
| 357 } | 357 } |
| 358 | 358 |
| 359 return nil | 359 return nil |
| 360 } | 360 } |
| 361 | 361 |
| 362 func (td *txnDataStoreData) putMulti(keys []ds.Key, vals []ds.PropertyLoadSaver,
cb ds.PutMultiCB) { | 362 func (td *txnDataStoreData) putMulti(keys []ds.Key, vals []ds.PropertyMap, cb ds
.PutMultiCB) { |
| 363 for i, k := range keys { | 363 for i, k := range keys { |
| 364 func() { | 364 func() { |
| 365 td.parent.Lock() | 365 td.parent.Lock() |
| 366 defer td.parent.Unlock() | 366 defer td.parent.Unlock() |
| 367 _, k = td.parent.entsKeyLocked(k) | 367 _, k = td.parent.entsKeyLocked(k) |
| 368 }() | 368 }() |
| 369 » » err := td.writeMutation(false, k, vals[i].(ds.PropertyMap)) | 369 » » err := td.writeMutation(false, k, vals[i]) |
| 370 if cb != nil { | 370 if cb != nil { |
| 371 cb(k, err) | 371 cb(k, err) |
| 372 } | 372 } |
| 373 } | 373 } |
| 374 } | 374 } |
| 375 | 375 |
| 376 func (td *txnDataStoreData) getMulti(keys []ds.Key, cb ds.GetMultiCB) error { | 376 func (td *txnDataStoreData) getMulti(keys []ds.Key, cb ds.GetMultiCB) error { |
| 377 return getMultiInner(keys, cb, func() (*memCollection, error) { | 377 return getMultiInner(keys, cb, func() (*memCollection, error) { |
| 378 err := error(nil) | 378 err := error(nil) |
| 379 for _, key := range keys { | 379 for _, key := range keys { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 410 | 410 |
| 411 func rpm(data []byte) (ds.PropertyMap, error) { | 411 func rpm(data []byte) (ds.PropertyMap, error) { |
| 412 ret := ds.PropertyMap{} | 412 ret := ds.PropertyMap{} |
| 413 err := ret.Read(bytes.NewBuffer(data), ds.WithContext, "", "") | 413 err := ret.Read(bytes.NewBuffer(data), ds.WithContext, "", "") |
| 414 return ret, err | 414 return ret, err |
| 415 } | 415 } |
| 416 | 416 |
| 417 type keyitem interface { | 417 type keyitem interface { |
| 418 Key() ds.Key | 418 Key() ds.Key |
| 419 } | 419 } |
| OLD | NEW |