code: func (s *Store) kvsSetTxn(tx *memdb.Txn, idx uint64, entry *structs.DirEntry, updateSession bool) error {
  	// Retrieve an existing KV pair
  	existing, err := tx.First("kvs", "id", entry.Key)
  	if err != nil {
  		return fmt.Errorf("failed kvs lookup: %s", err)
  	}
  
  	// Set the indexes.
  	if existing != nil {
  		entry.CreateIndex = existing.(*structs.DirEntry).CreateIndex
  	} else {
  		entry.CreateIndex = idx
  	}
  	entry.ModifyIndex = idx
  
  	// Preserve the existing session unless told otherwise. The "existing"
  	// session for a new entry is "no session".
  	if !updateSession {
  		if existing != nil {
  			entry.Session = existing.(*structs.DirEntry).Session
  		} else {
  			entry.Session = ""
  		}
  	}
  
  	// Store the kv pair in the state store and update the index.
  	if err := tx.Insert("kvs", entry); err != nil {
  		return fmt.Errorf("failed inserting kvs entry: %s", err)
  	}
  	if err := tx.Insert("index", &IndexEntry{"kvs", idx}); err != nil {
  		return fmt.Errorf("failed updating index: %s", err)
  	}
  
  	return nil
  }
docs: // kvsSetTxn is used to insert or update a key/value pair in the state
  // store. It is the inner method used and handles only the actual storage.
  // If updateSession is true, then the incoming entry will set the new
  // session (should be validated before calling this). Otherwise, we will keep
  // whatever the existing session is.