code: func (ds *datastore) PutObjectAtomic(kvObject KVObject) error {
  	var (
  		previous *store.KVPair
  		pair     *store.KVPair
  		err      error
  	)
  	if ds.sequential {
  		ds.Lock()
  		defer ds.Unlock()
  	}
  
  	if kvObject == nil {
  		return types.BadRequestErrorf("invalid KV Object : nil")
  	}
  
  	kvObjValue := kvObject.Value()
  
  	if kvObjValue == nil {
  		return types.BadRequestErrorf("invalid KV Object with a nil Value for key %s", Key(kvObject.Key()...))
  	}
  
  	if kvObject.Skip() {
  		goto add_cache
  	}
  
  	if kvObject.Exists() {
  		previous = &store.KVPair{Key: Key(kvObject.Key()...), LastIndex: kvObject.Index()}
  	} else {
  		previous = nil
  	}
  
  	_, pair, err = ds.store.AtomicPut(Key(kvObject.Key()...), kvObjValue, previous, nil)
  	if err != nil {
  		if err == store.ErrKeyExists {
  			return ErrKeyModified
  		}
  		return err
  	}
  
  	kvObject.SetIndex(pair.LastIndex)
  
  add_cache:
  	if ds.cache != nil {
  		// If persistent store is skipped, sequencing needs to
  		// happen in cache.
  		return ds.cache.add(kvObject, kvObject.Skip())
  	}
  
  	return nil
  }
docs: // PutObjectAtomic adds a new Record based on an object into the datastore