| 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 txnBuf | 5 package txnBuf |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "sync" | 9 "sync" |
| 10 | 10 |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 } | 309 } |
| 310 } | 310 } |
| 311 return nil | 311 return nil |
| 312 }() | 312 }() |
| 313 if err != nil { | 313 if err != nil { |
| 314 return err | 314 return err |
| 315 } | 315 } |
| 316 | 316 |
| 317 for i, itm := range data { | 317 for i, itm := range data { |
| 318 err := lme.GetOne(i) | 318 err := lme.GetOne(i) |
| 319 var cbErr error |
| 319 if err != nil { | 320 if err != nil { |
| 320 » » » cb(nil, err) | 321 » » » cbErr = cb(nil, err) |
| 321 } else if itm.data == nil { | 322 } else if itm.data == nil { |
| 322 » » » cb(nil, datastore.ErrNoSuchEntity) | 323 » » » cbErr = cb(nil, datastore.ErrNoSuchEntity) |
| 323 } else { | 324 } else { |
| 324 » » » cb(itm.data, nil) | 325 » » » cbErr = cb(itm.data, nil) |
| 326 » » } |
| 327 » » if cbErr != nil { |
| 328 » » » return cbErr |
| 325 } | 329 } |
| 326 } | 330 } |
| 327 return nil | 331 return nil |
| 328 } | 332 } |
| 329 | 333 |
| 330 func (t *txnBufState) deleteMulti(keys []*datastore.Key, cb datastore.DeleteMult
iCB, haveLock bool) error { | 334 func (t *txnBufState) deleteMulti(keys []*datastore.Key, cb datastore.DeleteMult
iCB, haveLock bool) error { |
| 331 encKeys, roots := toEncoded(keys) | 335 encKeys, roots := toEncoded(keys) |
| 332 | 336 |
| 333 err := func() error { | 337 err := func() error { |
| 334 if !haveLock { | 338 if !haveLock { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 348 return nil | 352 return nil |
| 349 }) | 353 }) |
| 350 impossible(err) | 354 impossible(err) |
| 351 return nil | 355 return nil |
| 352 }() | 356 }() |
| 353 if err != nil { | 357 if err != nil { |
| 354 return err | 358 return err |
| 355 } | 359 } |
| 356 | 360 |
| 357 for range keys { | 361 for range keys { |
| 358 » » cb(nil) | 362 » » if err := cb(nil); err != nil { |
| 363 » » » return err |
| 364 » » } |
| 359 } | 365 } |
| 360 | 366 |
| 361 return nil | 367 return nil |
| 362 } | 368 } |
| 363 | 369 |
| 364 func (t *txnBufState) fixKeys(keys []*datastore.Key) ([]*datastore.Key, error) { | 370 func (t *txnBufState) fixKeys(keys []*datastore.Key) ([]*datastore.Key, error) { |
| 365 lme := errors.NewLazyMultiError(len(keys)) | 371 lme := errors.NewLazyMultiError(len(keys)) |
| 366 realKeys := []*datastore.Key(nil) | 372 realKeys := []*datastore.Key(nil) |
| 367 for i, key := range keys { | 373 for i, key := range keys { |
| 368 if key.Incomplete() { | 374 if key.Incomplete() { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 385 if realKeys != nil { | 391 if realKeys != nil { |
| 386 return realKeys, err | 392 return realKeys, err |
| 387 } | 393 } |
| 388 return keys, err | 394 return keys, err |
| 389 } | 395 } |
| 390 | 396 |
| 391 func (t *txnBufState) putMulti(keys []*datastore.Key, vals []datastore.PropertyM
ap, cb datastore.PutMultiCB, haveLock bool) error { | 397 func (t *txnBufState) putMulti(keys []*datastore.Key, vals []datastore.PropertyM
ap, cb datastore.PutMultiCB, haveLock bool) error { |
| 392 keys, err := t.fixKeys(keys) | 398 keys, err := t.fixKeys(keys) |
| 393 if err != nil { | 399 if err != nil { |
| 394 for _, e := range err.(errors.MultiError) { | 400 for _, e := range err.(errors.MultiError) { |
| 395 » » » cb(nil, e) | 401 » » » if err := cb(nil, e); err != nil { |
| 402 » » » » return err |
| 403 » » » } |
| 396 } | 404 } |
| 397 return nil | 405 return nil |
| 398 } | 406 } |
| 399 | 407 |
| 400 encKeys, roots := toEncoded(keys) | 408 encKeys, roots := toEncoded(keys) |
| 401 | 409 |
| 402 err = func() error { | 410 err = func() error { |
| 403 if !haveLock { | 411 if !haveLock { |
| 404 t.Lock() | 412 t.Lock() |
| 405 defer t.Unlock() | 413 defer t.Unlock() |
| (...skipping 11 matching lines...) Expand all Loading... |
| 417 return nil | 425 return nil |
| 418 }) | 426 }) |
| 419 impossible(err) | 427 impossible(err) |
| 420 return nil | 428 return nil |
| 421 }() | 429 }() |
| 422 if err != nil { | 430 if err != nil { |
| 423 return err | 431 return err |
| 424 } | 432 } |
| 425 | 433 |
| 426 for _, k := range keys { | 434 for _, k := range keys { |
| 427 » » cb(k, nil) | 435 » » if err := cb(k, nil); err != nil { |
| 436 » » » return err |
| 437 » » } |
| 428 } | 438 } |
| 429 return nil | 439 return nil |
| 430 } | 440 } |
| 431 | 441 |
| 432 func commitToReal(s *txnBufState) error { | 442 func commitToReal(s *txnBufState) error { |
| 433 toPut, toPutKeys, toDel := s.effect() | 443 toPut, toPutKeys, toDel := s.effect() |
| 434 | 444 |
| 435 return parallel.FanOutIn(func(ch chan<- func() error) { | 445 return parallel.FanOutIn(func(ch chan<- func() error) { |
| 436 if len(toPut) > 0 { | 446 if len(toPut) > 0 { |
| 437 ch <- func() error { | 447 ch <- func() error { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 // plus a stringset of all the encoded root keys that `keys` represents. | 547 // plus a stringset of all the encoded root keys that `keys` represents. |
| 538 func toEncoded(keys []*datastore.Key) (full []string, roots stringset.Set) { | 548 func toEncoded(keys []*datastore.Key) (full []string, roots stringset.Set) { |
| 539 roots = stringset.New(len(keys)) | 549 roots = stringset.New(len(keys)) |
| 540 full = make([]string, len(keys)) | 550 full = make([]string, len(keys)) |
| 541 for i, k := range keys { | 551 for i, k := range keys { |
| 542 roots.Add(string(serialize.ToBytes(k.Root()))) | 552 roots.Add(string(serialize.ToBytes(k.Root()))) |
| 543 full[i] = string(serialize.ToBytes(k)) | 553 full[i] = string(serialize.ToBytes(k)) |
| 544 } | 554 } |
| 545 return | 555 return |
| 546 } | 556 } |
| OLD | NEW |