'Determining write nodes in Cassandra

I've just started reading about Cassandra and I can't quite understand how Cassandra manages to decide which nodes should it write the data to.

What I understand, is that Cassandra uses a part of primary key, specifically partition key, and partitioner to get a token by hashing the partition key, therefore a node/vnode to which that token is bound to. Now let's say I have 2 nodes in my cluster, each has 256 vnodes on it + I'm not using any clustering keys, just a simple PK and a bunch of simple columns. Hashing partition key would clearly determine where the data should go. By this logic, there would be only 512 unique records available for storage. Would be funny if true. So am I wrong at the partitioner part?



Solution 1:[1]

You want to have piping in your application. That doesn't happen in the way you are trying. The way you write commands in your terminal is different from the way Bash and then OS treats them.

This example might help you, copied from another SO question (view question):

package main

import (
    "os"
    "os/exec"
)

func main() {
    c1 := exec.Command("ls")
    c2 := exec.Command("wc", "-l")
    c2.Stdin, _ = c1.StdoutPipe()
    c2.Stdout = os.Stdout
    _ = c2.Start()
    _ = c1.Run()
    _ = c2.Wait()
}

Solution 2:[2]

Thanks for your answers. I tried to improve it with your recommendations with piping.

Now it looks like this:

func main() {
    cmd := exec.Command("/bin/bash", "-c", "ftp")

    stdin, err := cmd.StdinPipe()
    if err != nil {
        log.Fatal(err)
    }
    stdout, err := cmd.StdoutPipe()
    if err != nil {
        log.Fatal(err)
    }
    stderr, err := cmd.StderrPipe()
    if err != nil {
        log.Fatal(err)
    }

    go func() {
        defer stdin.Close()

        stdinCommand := "status\n"
        fmt.Print(time.Now().UTC().Format("15:04:05") + " STDIN: " + stdinCommand)
        io.WriteString(stdin, stdinCommand)

        time.Sleep(1 * time.Second)

        stdinCommand = "help\n"
        fmt.Print(time.Now().UTC().Format("15:04:05") + " STDIN: " + stdinCommand)
        io.WriteString(stdin, stdinCommand)
        time.Sleep(2 * time.Second)
    }()

    scanner := bufio.NewScanner(stdout)
    go func() {
        for scanner.Scan() {
            fmt.Println(time.Now().UTC().Format("15:04:05") + " STDOUT: " + scanner.Text())
        }
    }()

    scannerError := bufio.NewScanner(stderr)
    go func() {
        for scannerError.Scan() {
            fmt.Println(time.Now().UTC().Format("15:04:05") + " STDERR: " + scanner.Text())
        }
    }()

    if err := cmd.Run(); err != nil {
        log.Fatal(err)
    }
    fmt.Print(time.Now().UTC().Format("15:04:05") + " done")
}

The output now looks like this:

15:24:26 STDIN: status
15:24:27 STDIN: help
15:24:29 STDOUT: Not connected.
15:24:29 STDOUT: No proxy connection.
15:24:29 STDOUT: Connecting using address family: any.
15:24:29 STDOUT: Mode: ; Type: ; Form: ; Structure: 
15:24:29 STDOUT: Verbose: off; Bell: off; Prompting: on; Globbing: on
15:24:29 STDOUT: Store unique: off; Receive unique: off
15:24:29 STDOUT: Case: off; CR stripping: on
15:24:29 STDOUT: Quote control characters: off
15:24:29 STDOUT: Ntrans: off
15:24:29 STDOUT: Nmap: off
15:24:29 STDOUT: Hash mark printing: off; Use of PORT cmds: on
15:24:29 STDOUT: Tick counter printing: off
15:24:29 STDOUT: Commands may be abbreviated.  Commands are:
15:24:29 STDOUT: 
15:24:29 STDOUT: !              dir             mdelete         qc              site
15:24:29 STDOUT: $              disconnect      mdir            sendport        size
15:24:29 STDOUT: account                exit            mget            put             status
15:24:29 STDOUT: append         form            mkdir           pwd             struct
15:24:29 STDOUT: ascii          get             mls             quit            system
15:24:29 STDOUT: bell           glob            mode            quote           sunique
15:24:29 STDOUT: binary         hash            modtime         recv            tenex
15:24:29 STDOUT: bye            help            mput            reget           tick
15:24:29 STDOUT: case           idle            newer           rstatus         trace
15:24:29 done

Do you have a hint, what I need to change to get the response for "status" directly behind the input and afterwards send "help" to get the help response. In the end I'd like to send "exit" to exit the program. With the current version it automatically exits as long as I have "defer stdin.Close()" included. When I remove it, I do not get the output.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mostafa Talebi
Solution 2 bmm