Skip to content

Loading…

consistency guarantees? #22

Open
mwotton opened this Issue · 6 comments

2 participants

@mwotton

I may be doing something extremely silly, but I don't seem to be getting the consistency guarantees I'd expect.

This code ought to have 100 threads all inserting their particular value into all the keys from "1" to "100". At the end, I'd expect that all keys would have all the values inserted into them. Instead, many are missing.

{-# LANGUAGE OverloadedStrings #-}

import           Control.Applicative
import           Control.Concurrent.Async
import           Control.Monad
import qualified Data.ByteString.Lazy.Char8 as LBS
import qualified Data.Set                   as S
import           Network.Riak

instance (Ord a, Show a) => Resolvable (S.Set a) where
  resolve = S.union

keys :: [LBS.ByteString]
keys = map (LBS.pack . show) [1..100]

insertInto id conn = do
  forM_ keys $ \key ->
    modify conn "the_bucket"  key All All All  (\x -> return (maybe (S.singleton id) (S.insert id) x, ()))

deleteBucket conn bucket = do
  keys <- foldKeys conn bucket (\acc k -> return (k:acc)) []
  forM_ keys $ \k -> delete conn bucket k All

main :: IO ()
main = do
  conn <- connect defaultClient
  ping conn
  listBuckets conn >>= print
  deleteBucket conn "the_bucket"

  mapConcurrently (\x -> connect defaultClient >>= insertInto x) keys
  let correct = S.fromList keys
  forM_ keys $ \key -> do
    val <- (fmap fst) <$> get conn "the_bucket" key All
    if val /= Just correct
      then putStrLn ("failed for " ++ show (key,val))
      else return ()

  putStrLn "worked!"
@markhibberd

@mwotton What does the cluster your testing against look like? Number of nodes, lww/allow siblings config etc...

@markhibberd

Actually looking at the code a bit more, I am almost certain you have lww set to true or allow siblings set to false (or both) if this is failing. Regrettably these are the default settings on 1.x, so your resolvable would never be called.

@mwotton

@markhibberd it's ubuntu's default - i'll try turning lww off. (how do you do that?)

@markhibberd

Each node has an etc/app.config. search for:

 {allow_mult,...}
 {last_write_wins,...}

I think there will be global ones and default bucket props.

allow_mult should be true, last_write_wins should be false. Not at my machine at moment, but if you keep having issues I can send through my config tonight.

@mwotton

ah, cool. thanks. last_write_wins was false, but allow_mult was false too. tried setting it using the haskell client, but now I'm getting protobuf errors...

rhino ➜  ~/projects/meanpath/RiakTest  dist/build/RiakTest/RiakTest
fromList ["gsets","testing","the_bucket3","the_bucket"]
RiakTest: Riak network error (Network.Riak.Connection.Internal.recvGetN): Text.ProtocolBuffers.WireMessage.unknown: Unknown field found or failure parsing field (e.g. unexpected Enum value):
  (message type name,field id number,wire type code,bytes read) == (Content,FieldId {getFieldId = 11},WireType {getWireType = 0},40)
  when processing ProtoName {protobufName = FIName ".Protocol.Content", haskellPrefix = [MName "Network",MName "Riak"], parentModule = [MName "Protocol"], baseName = MName "Content"}

anyway, i'll keep digging. thanks for the help.

@markhibberd

Also of note is PR #19 which may help with the protocol issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.