本文整理匯總了Golang中camlistore/org/pkg/sorted.CheckSizes函數的典型用法代碼示例。如果您正苦於以下問題:Golang CheckSizes函數的具體用法?Golang CheckSizes怎麽用?Golang CheckSizes使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CheckSizes函數的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Set
func (is *kvis) Set(key, value string) error {
if err := sorted.CheckSizes(key, value); err != nil {
log.Printf("Skipping storing (%q:%q): %v", key, value, err)
return nil
}
return is.db.Set([]byte(key), []byte(value))
}
示例2: CommitBatch
func (kv *keyValue) CommitBatch(bm sorted.BatchMutation) error {
b, ok := bm.(batch)
if !ok {
return errors.New("invalid batch type")
}
kv.mu.Lock()
defer kv.mu.Unlock()
for _, m := range b.Mutations() {
if m.IsDelete() {
if err := kv.db.Remove(bson.M{mgoKey: m.Key()}); err != nil && err != mgo.ErrNotFound {
return err
}
} else {
if err := sorted.CheckSizes(m.Key(), m.Value()); err != nil {
log.Printf("Skipping storing (%q:%q): %v", m.Key(), m.Value(), err)
continue
}
if _, err := kv.db.Upsert(&bson.M{mgoKey: m.Key()}, &bson.M{mgoKey: m.Key(), mgoValue: m.Value()}); err != nil {
return err
}
}
}
return nil
}
示例3: Set
func (kv *keyValue) Set(key, value string) error {
if err := sorted.CheckSizes(key, value); err != nil {
return err
}
kv.mu.Lock()
defer kv.mu.Unlock()
_, err := kv.db.Upsert(&bson.M{mgoKey: key}, &bson.M{mgoKey: key, mgoValue: value})
return err
}
示例4: Set
func (kv *keyValue) Set(key, value string) error {
if err := sorted.CheckSizes(key, value); err != nil {
log.Printf("Skipping storing (%q:%q): %v", key, value, err)
return nil
}
kv.mu.Lock()
defer kv.mu.Unlock()
_, err := kv.db.Upsert(&bson.M{mgoKey: key}, &bson.M{mgoKey: key, mgoValue: value})
return err
}
示例5: Set
func (lvb *lvbatch) Set(key, value string) {
lvb.errMu.Lock()
defer lvb.errMu.Unlock()
if lvb.err != nil {
return
}
if err := sorted.CheckSizes(key, value); err != nil {
log.Printf("Skipping storing (%q:%q): %v", key, value, err)
return
}
lvb.batch.Put([]byte(key), []byte(value))
}
示例6: Set
func (kv *KeyValue) Set(key, value string) error {
if err := sorted.CheckSizes(key, value); err != nil {
return err
}
if kv.Serial {
kv.mu.Lock()
defer kv.mu.Unlock()
}
if kv.SetFunc != nil {
return kv.SetFunc(kv.DB, key, value)
}
_, err := kv.DB.Exec(kv.sql("REPLACE INTO /*TPRE*/rows (k, v) VALUES (?, ?)"), key, value)
return err
}
示例7: Set
func (b *batchTx) Set(key, value string) {
if b.err != nil {
return
}
if err := sorted.CheckSizes(key, value); err != nil {
log.Printf("Skipping storing (%q:%q): %v", key, value, err)
return
}
if b.kv.BatchSetFunc != nil {
b.err = b.kv.BatchSetFunc(b.tx, key, value)
return
}
_, b.err = b.tx.Exec(b.kv.sql("REPLACE INTO /*TPRE*/rows (k, v) VALUES (?, ?)"), key, value)
}
示例8: Set
func (lvb *lvbatch) Set(key, value string) {
lvb.errMu.Lock()
defer lvb.errMu.Unlock()
if lvb.err != nil {
return
}
if err := sorted.CheckSizes(key, value); err != nil {
if err == sorted.ErrKeyTooLarge {
lvb.err = fmt.Errorf("%v: %v", err, key)
} else {
lvb.err = fmt.Errorf("%v: %v", err, value)
}
return
}
lvb.batch.Put([]byte(key), []byte(value))
}
示例9: Set
func (kv *KeyValue) Set(key, value string) error {
if err := sorted.CheckSizes(key, value); err != nil {
return err
}
kv.mu.RLock()
err := kv.buf.Set(key, value)
kv.mu.RUnlock()
if err == nil {
kv.bufMu.Lock()
kv.buffered += int64(len(key) + len(value))
doFlush := kv.buffered > kv.maxBuffer
kv.bufMu.Unlock()
if doFlush {
err = kv.Flush()
}
}
return err
}
示例10: Set
func (kv *KeyValue) Set(key, value string) error {
if err := sorted.CheckSizes(key, value); err != nil {
log.Printf("Skipping storing (%q:%q): %v", key, value, err)
return nil
}
kv.mu.RLock()
err := kv.buf.Set(key, value)
kv.mu.RUnlock()
if err == nil {
kv.bufMu.Lock()
kv.buffered += int64(len(key) + len(value))
doFlush := kv.buffered > kv.maxBuffer
kv.bufMu.Unlock()
if doFlush {
err = kv.Flush()
}
}
return err
}
示例11: CommitBatch
func (kv *KeyValue) CommitBatch(bm sorted.BatchMutation) error {
kv.mu.RLock()
defer kv.mu.RUnlock()
b, ok := bm.(*batch)
if !ok {
return fmt.Errorf("unexpected BatchMutation type %T", bm)
}
var (
// A batch mutation for applying this mutation to the buffer.
bmbuf = kv.buf.BeginBatch()
// A lazily created batch mutation for deleting from the backing
// storage; this should be rare. (See Delete above.)
bmback sorted.BatchMutation
)
for _, m := range b.mods {
if m.isDelete {
bmbuf.Delete(m.key)
if bmback == nil {
bmback = kv.back.BeginBatch()
}
bmback.Delete(m.key)
continue
} else {
if err := sorted.CheckSizes(m.key, m.value); err != nil {
log.Printf("Skipping storing (%q:%q): %v", m.key, m.value, err)
continue
}
}
bmbuf.Set(m.key, m.value)
}
if err := kv.buf.CommitBatch(bmbuf); err != nil {
return err
}
if bmback != nil {
return kv.back.CommitBatch(bmback)
}
return nil
}
示例12: CommitBatch
func (is *kvis) CommitBatch(bm sorted.BatchMutation) error {
b, ok := bm.(batch)
if !ok {
return errors.New("invalid batch type")
}
is.txmu.Lock()
defer is.txmu.Unlock()
good := false
defer func() {
if !good {
is.db.Rollback()
}
}()
if err := is.db.BeginTransaction(); err != nil {
return err
}
for _, m := range b.Mutations() {
if m.IsDelete() {
if err := is.db.Delete([]byte(m.Key())); err != nil {
return err
}
} else {
if err := sorted.CheckSizes(m.Key(), m.Value()); err != nil {
log.Printf("Skipping storing (%q:%q): %v", m.Key(), m.Value(), err)
continue
}
if err := is.db.Set([]byte(m.Key()), []byte(m.Value())); err != nil {
return err
}
}
}
good = true
return is.db.Commit()
}
示例13: CommitBatch
func (kv *keyValue) CommitBatch(bm sorted.BatchMutation) error {
b, ok := bm.(batch)
if !ok {
return errors.New("invalid batch type")
}
kv.mu.Lock()
defer kv.mu.Unlock()
for _, m := range b.Mutations() {
if m.IsDelete() {
if err := kv.db.Remove(bson.M{mgoKey: m.Key()}); err != nil {
return err
}
} else {
if err := sorted.CheckSizes(m.Key(), m.Value()); err != nil {
return err
}
if _, err := kv.db.Upsert(&bson.M{mgoKey: m.Key()}, &bson.M{mgoKey: m.Key(), mgoValue: m.Value()}); err != nil {
return err
}
}
}
return nil
}