Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6858F200C10 for ; Fri, 20 Jan 2017 02:12:38 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 67160160B5A; Fri, 20 Jan 2017 01:12:38 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 15C16160B5F for ; Fri, 20 Jan 2017 02:12:35 +0100 (CET) Received: (qmail 10688 invoked by uid 500); 20 Jan 2017 01:12:35 -0000 Mailing-List: contact commits-help@helix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@helix.apache.org Delivered-To: mailing list commits@helix.apache.org Received: (qmail 10597 invoked by uid 99); 20 Jan 2017 01:12:34 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Jan 2017 01:12:34 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 89A583A47AD for ; Fri, 20 Jan 2017 01:12:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r1779549 [7/18] - in /helix/site-content: ./ 0.6.1-incubating-docs/ 0.6.1-incubating-docs/recipes/ 0.6.1-incubating-docs/releasenotes/ 0.6.2-incubating-docs/ 0.6.2-incubating-docs/recipes/ 0.6.2-incubating-docs/releasenotes/ 0.6.3-docs/ 0.6... Date: Fri, 20 Jan 2017 01:12:30 -0000 To: commits@helix.apache.org From: lxia@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20170120011233.89A583A47AD@svn01-us-west.apache.org> archived-at: Fri, 20 Jan 2017 01:12:38 -0000 Added: helix/site-content/0.6.7-docs/Quickstart.html URL: http://svn.apache.org/viewvc/helix/site-content/0.6.7-docs/Quickstart.html?rev=1779549&view=auto ============================================================================== --- helix/site-content/0.6.7-docs/Quickstart.html (added) +++ helix/site-content/0.6.7-docs/Quickstart.html Fri Jan 20 01:12:25 2017 @@ -0,0 +1,860 @@ + + + + + + + + Apache Helix - Quickstart + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ +
+ +
+
+ +
+
+
+
+ +

+
+ +
+
+

Get Helix

+

First, let's get Helix. Either build it, or download it.

+
+

Build

+
+
git clone https://git-wip-us.apache.org/repos/asf/helix.git
+cd helix
+git checkout tags/helix-0.6.7
+mvn install package -DskipTests
+cd helix-core/target/helix-core-pkg/bin # This folder contains all the scripts used in following sections
+chmod +x *
+
+
+
+
+

Download

+

Download the 0.6.7 release package here

+
+
+
+

Overview

+

In this Quickstart, we'll set up a master-slave replicated, partitioned system. Then we'll demonstrate how to add a node, rebalance the partitions, and show how Helix manages failover.

+
+
+

Let's Do It

+

Helix provides command line interfaces to set up the cluster and view the cluster state. The best way to understand how Helix views a cluster is to build a cluster.

+
+

Get to the Tools Directory

+

If you built the code:

+
+
cd helix/helix/helix-core/target/helix-core-pkg/bin
+
+
+

If you downloaded the release package, extract it.

+
+
+
+

Short Version

+

You can observe the components working together in this demo, which does the following:

+
    +
  • Create a cluster
  • +
  • Add 2 nodes (participants) to the cluster
  • +
  • Set up a resource with 6 partitions and 2 replicas: 1 Master, and 1 Slave per partition
  • +
  • Show the cluster state after Helix balances the partitions
  • +
  • Add a third node
  • +
  • Show the cluster state. Note that the third node has taken mastership of 2 partitions.
  • +
  • Kill the third node (Helix takes care of failover)
  • +
  • Show the cluster state. Note that the two surviving nodes take over mastership of the partitions from the failed node
  • +
+
+

Run the Demo

+
+
cd helix/helix/helix-core/target/helix-core-pkg/bin
+./quickstart.sh
+
+
+
+

The Initial Setup

+

2 nodes are set up and the partitions are rebalanced.

+

The cluster state is as follows:

+
+
CLUSTER STATE: After starting 2 nodes
+                localhost_12000    localhost_12001
+MyResource_0           M                  S
+MyResource_1           S                  M
+MyResource_2           M                  S
+MyResource_3           M                  S
+MyResource_4           S                  M
+MyResource_5           S                  M
+
+
+

Note there is one master and one slave per partition.

+
+
+

Add a Node

+

A third node is added and the cluster is rebalanced.

+

The cluster state changes to:

+
+
CLUSTER STATE: After adding a third node
+               localhost_12000    localhost_12001    localhost_12002
+MyResource_0          S                  M                  S
+MyResource_1          S                  S                  M
+MyResource_2          M                  S                  S
+MyResource_3          S                  S                  M
+MyResource_4          M                  S                  S
+MyResource_5          S                  M                  S
+
+
+

Note there is one master and two slaves per partition. This is expected because there are three nodes.

+
+
+

Kill a Node

+

Finally, a node is killed to simulate a failure

+

Helix makes sure each partition has a master. The cluster state changes to:

+
+
CLUSTER STATE: After the 3rd node stops/crashes
+               localhost_12000    localhost_12001    localhost_12002
+MyResource_0          S                  M                  -
+MyResource_1          S                  M                  -
+MyResource_2          M                  S                  -
+MyResource_3          M                  S                  -
+MyResource_4          M                  S                  -
+MyResource_5          S                  M                  -
+
+
+
+
+
+
+

Long Version

+

Now you can run the same steps by hand. In this detailed version, we'll do the following:

+
    +
  • Define a cluster
  • +
  • Add two nodes to the cluster
  • +
  • Add a 6-partition resource with 1 master and 2 slave replicas per partition
  • +
  • Verify that the cluster is healthy and inspect the Helix view
  • +
  • Expand the cluster: add a few nodes and rebalance the partitions
  • +
  • Failover: stop a node and verify the mastership transfer
  • +
+
+

Install and Start ZooKeeper

+

Zookeeper can be started in standalone mode or replicated mode.

+

More information is available at

+ +

In this example, let's start zookeeper in local mode.

+
+

Start ZooKeeper Locally on Port 2199

+
+
./start-standalone-zookeeper.sh 2199 &
+
+
+
+
+
+

Define the Cluster

+

The helix-admin tool is used for cluster administration tasks. In the Quickstart, we'll use the command line interface. Helix supports a REST interface as well.

+

zookeeper_address is of the format host:port e.g localhost:2199 for standalone or host1:port,host2:port for multi-node.

+

Next, we'll set up a cluster MYCLUSTER cluster with these attributes:

+
    +
  • 3 instances running on localhost at ports 12913,12914,12915
  • +
  • One database named myDB with 6 partitions
  • +
  • Each partition will have 3 replicas with 1 master, 2 slaves
  • +
  • ZooKeeper running locally at localhost:2199
  • +
+
+

Create the Cluster MYCLUSTER

+
+
# ./helix-admin.sh --zkSvr <zk_address> --addCluster <clustername>
+./helix-admin.sh --zkSvr localhost:2199 --addCluster MYCLUSTER
+
+
+
+
+
+

Add Nodes to the Cluster

+

In this case we'll add three nodes: localhost:12913, localhost:12914, localhost:12915

+
+
# helix-admin.sh --zkSvr <zk_address>  --addNode <clustername> <host:port>
+./helix-admin.sh --zkSvr localhost:2199  --addNode MYCLUSTER localhost:12913
+./helix-admin.sh --zkSvr localhost:2199  --addNode MYCLUSTER localhost:12914
+./helix-admin.sh --zkSvr localhost:2199  --addNode MYCLUSTER localhost:12915
+
+
+
+
+

Define the Resource and Partitioning

+

In this example, the resource is a database, partitioned 6 ways. Note that in a production system, it's common to over-partition for better load balancing. Helix has been used in production to manage hundreds of databases each with 10s or 100s of partitions running on 10s of physical nodes.

+
+

Create a Database with 6 Partitions using the MasterSlave State Model

+

Helix ensures there will be exactly one master for each partition.

+
+
# helix-admin.sh --zkSvr <zk_address> --addResource <clustername> <resourceName> <numPartitions> <StateModelName>
+./helix-admin.sh --zkSvr localhost:2199 --addResource MYCLUSTER myDB 6 MasterSlave
+
+
+
+
+

Let Helix Assign Partitions to Nodes

+

This command will distribute the partitions amongst all the nodes in the cluster. In this example, each partition has 3 replicas.

+
+
# helix-admin.sh --zkSvr <zk_address> --rebalance <clustername> <resourceName> <replication factor>
+./helix-admin.sh --zkSvr localhost:2199 --rebalance MYCLUSTER myDB 3
+
+
+

Now the cluster is defined in ZooKeeper. The nodes (localhost:12913, localhost:12914, localhost:12915) and resource (myDB, with 6 partitions using the MasterSlave model) are all properly configured. And the IdealState has been calculated, assuming a replication factor of 3.

+
+
+
+

Start the Helix Controller

+

Now that the cluster is defined in ZooKeeper, the Helix controller can manage the cluster.

+
+
# Start the cluster manager, which will manage MYCLUSTER
+./run-helix-controller.sh --zkSvr localhost:2199 --cluster MYCLUSTER 2>&1 > /tmp/controller.log &
+
+
+
+
+

Start up the Cluster to be Managed

+

We've started up ZooKeeper, defined the cluster, the resources, the partitioning, and started up the Helix controller. Next, we'll start up the nodes of the system to be managed. Each node is a Participant, which is an instance of the system component to be managed. Helix assigns work to Participants, keeps track of their roles and health, and takes action when a node fails.

+
+
# start up each instance.  These are mock implementations that are actively managed by Helix
+./start-helix-participant.sh --zkSvr localhost:2199 --cluster MYCLUSTER --host localhost --port 12913 --stateModelType MasterSlave 2>&1 > /tmp/participant_12913.log
+./start-helix-participant.sh --zkSvr localhost:2199 --cluster MYCLUSTER --host localhost --port 12914 --stateModelType MasterSlave 2>&1 > /tmp/participant_12914.log
+./start-helix-participant.sh --zkSvr localhost:2199 --cluster MYCLUSTER --host localhost --port 12915 --stateModelType MasterSlave 2>&1 > /tmp/participant_12915.log
+
+
+
+
+

Inspect the Cluster

+

Now, let's see the Helix view of our cluster. We'll work our way down as follows:

+
+
Clusters -> MYCLUSTER -> instances -> instance detail
+                      -> resources -> resource detail
+                      -> partitions
+
+
+

A single Helix controller can manage multiple clusters, though so far, we've only defined one cluster. Let's see:

+
+
# List existing clusters
+./helix-admin.sh --zkSvr localhost:2199 --listClusters
+
+Existing clusters:
+MYCLUSTER
+
+
+

Now, let's see the Helix view of MYCLUSTER:

+
+
# helix-admin.sh --zkSvr <zk_address> --listClusterInfo <clusterName>
+./helix-admin.sh --zkSvr localhost:2199 --listClusterInfo MYCLUSTER
+
+Existing resources in cluster MYCLUSTER:
+myDB
+Instances in cluster MYCLUSTER:
+localhost_12915
+localhost_12914
+localhost_12913
+
+
+

Let's look at the details of an instance:

+
+
# ./helix-admin.sh --zkSvr <zk_address> --listInstanceInfo <clusterName> <InstanceName>
+./helix-admin.sh --zkSvr localhost:2199 --listInstanceInfo MYCLUSTER localhost_12913
+
+InstanceConfig: {
+  "id" : "localhost_12913",
+  "mapFields" : {
+  },
+  "listFields" : {
+  },
+  "simpleFields" : {
+    "HELIX_ENABLED" : "true",
+    "HELIX_HOST" : "localhost",
+    "HELIX_PORT" : "12913"
+  }
+}
+
+
+
+

Query Information about a Resource

+
+
# helix-admin.sh --zkSvr <zk_address> --listResourceInfo <clusterName> <resourceName>
+./helix-admin.sh --zkSvr localhost:2199 --listResourceInfo MYCLUSTER myDB
+
+IdealState for myDB:
+{
+  "id" : "myDB",
+  "mapFields" : {
+    "myDB_0" : {
+      "localhost_12913" : "SLAVE",
+      "localhost_12914" : "MASTER",
+      "localhost_12915" : "SLAVE"
+    },
+    "myDB_1" : {
+      "localhost_12913" : "SLAVE",
+      "localhost_12914" : "SLAVE",
+      "localhost_12915" : "MASTER"
+    },
+    "myDB_2" : {
+      "localhost_12913" : "MASTER",
+      "localhost_12914" : "SLAVE",
+      "localhost_12915" : "SLAVE"
+    },
+    "myDB_3" : {
+      "localhost_12913" : "SLAVE",
+      "localhost_12914" : "SLAVE",
+      "localhost_12915" : "MASTER"
+    },
+    "myDB_4" : {
+      "localhost_12913" : "MASTER",
+      "localhost_12914" : "SLAVE",
+      "localhost_12915" : "SLAVE"
+    },
+    "myDB_5" : {
+      "localhost_12913" : "SLAVE",
+      "localhost_12914" : "MASTER",
+      "localhost_12915" : "SLAVE"
+    }
+  },
+  "listFields" : {
+    "myDB_0" : [ "localhost_12914", "localhost_12913", "localhost_12915" ],
+    "myDB_1" : [ "localhost_12915", "localhost_12913", "localhost_12914" ],
+    "myDB_2" : [ "localhost_12913", "localhost_12915", "localhost_12914" ],
+    "myDB_3" : [ "localhost_12915", "localhost_12913", "localhost_12914" ],
+    "myDB_4" : [ "localhost_12913", "localhost_12914", "localhost_12915" ],
+    "myDB_5" : [ "localhost_12914", "localhost_12915", "localhost_12913" ]
+  },
+  "simpleFields" : {
+    "IDEAL_STATE_MODE" : "AUTO",
+    "REBALANCE_MODE" : "SEMI_AUTO",
+    "NUM_PARTITIONS" : "6",
+    "REPLICAS" : "3",
+    "STATE_MODEL_DEF_REF" : "MasterSlave",
+    "STATE_MODEL_FACTORY_NAME" : "DEFAULT"
+  }
+}
+
+ExternalView for myDB:
+{
+  "id" : "myDB",
+  "mapFields" : {
+    "myDB_0" : {
+      "localhost_12913" : "SLAVE",
+      "localhost_12914" : "MASTER",
+      "localhost_12915" : "SLAVE"
+    },
+    "myDB_1" : {
+      "localhost_12913" : "SLAVE",
+      "localhost_12914" : "SLAVE",
+      "localhost_12915" : "MASTER"
+    },
+    "myDB_2" : {
+      "localhost_12913" : "MASTER",
+      "localhost_12914" : "SLAVE",
+      "localhost_12915" : "SLAVE"
+    },
+    "myDB_3" : {
+      "localhost_12913" : "SLAVE",
+      "localhost_12914" : "SLAVE",
+      "localhost_12915" : "MASTER"
+    },
+    "myDB_4" : {
+      "localhost_12913" : "MASTER",
+      "localhost_12914" : "SLAVE",
+      "localhost_12915" : "SLAVE"
+    },
+    "myDB_5" : {
+      "localhost_12913" : "SLAVE",
+      "localhost_12914" : "MASTER",
+      "localhost_12915" : "SLAVE"
+    }
+  },
+  "listFields" : {
+  },
+  "simpleFields" : {
+    "BUCKET_SIZE" : "0"
+  }
+}
+
+
+

Now, let's look at one of the partitions:

+
+
# helix-admin.sh --zkSvr <zk_address> --listResourceInfo <clusterName> <partition>
+./helix-admin.sh --zkSvr localhost:2199 --listResourceInfo mycluster myDB_0
+
+
+
+
+
+

Expand the Cluster

+

Next, we'll show how Helix does the work that you'd otherwise have to build into your system. When you add capacity to your cluster, you want the work to be evenly distributed. In this example, we started with 3 nodes, with 6 partitions. The partitions were evenly balanced, 2 masters and 4 slaves per node. Let's add 3 more nodes: localhost:12916, localhost:12917, localhost:12918

+
+
./helix-admin.sh --zkSvr localhost:2199  --addNode MYCLUSTER localhost:12916
+./helix-admin.sh --zkSvr localhost:2199  --addNode MYCLUSTER localhost:12917
+./helix-admin.sh --zkSvr localhost:2199  --addNode MYCLUSTER localhost:12918
+
+
+

And start up these instances:

+
+
# start up each instance.  These are mock implementations that are actively managed by Helix
+./start-helix-participant.sh --zkSvr localhost:2199 --cluster MYCLUSTER --host localhost --port 12916 --stateModelType MasterSlave 2>&1 > /tmp/participant_12916.log
+./start-helix-participant.sh --zkSvr localhost:2199 --cluster MYCLUSTER --host localhost --port 12917 --stateModelType MasterSlave 2>&1 > /tmp/participant_12917.log
+./start-helix-participant.sh --zkSvr localhost:2199 --cluster MYCLUSTER --host localhost --port 12918 --stateModelType MasterSlave 2>&1 > /tmp/participant_12918.log
+
+
+

And now, let Helix do the work for you. To shift the work, simply rebalance. After the rebalance, each node will have one master and two slaves.

+
+
./helix-admin.sh --zkSvr localhost:2199 --rebalance MYCLUSTER myDB 3
+
+
+
+
+

View the Cluster

+

OK, let's see how it looks:

+
+
./helix-admin.sh --zkSvr localhost:2199 --listResourceInfo MYCLUSTER myDB
+
+IdealState for myDB:
+{
+  "id" : "myDB",
+  "mapFields" : {
+    "myDB_0" : {
+      "localhost_12913" : "SLAVE",
+      "localhost_12914" : "SLAVE",
+      "localhost_12917" : "MASTER"
+    },
+    "myDB_1" : {
+      "localhost_12916" : "SLAVE",
+      "localhost_12917" : "SLAVE",
+      "localhost_12918" : "MASTER"
+    },
+    "myDB_2" : {
+      "localhost_12913" : "MASTER",
+      "localhost_12917" : "SLAVE",
+      "localhost_12918" : "SLAVE"
+    },
+    "myDB_3" : {
+      "localhost_12915" : "MASTER",
+      "localhost_12917" : "SLAVE",
+      "localhost_12918" : "SLAVE"
+    },
+    "myDB_4" : {
+      "localhost_12916" : "MASTER",
+      "localhost_12917" : "SLAVE",
+      "localhost_12918" : "SLAVE"
+    },
+    "myDB_5" : {
+      "localhost_12913" : "SLAVE",
+      "localhost_12914" : "MASTER",
+      "localhost_12915" : "SLAVE"
+    }
+  },
+  "listFields" : {
+    "myDB_0" : [ "localhost_12917", "localhost_12913", "localhost_12914" ],
+    "myDB_1" : [ "localhost_12918", "localhost_12917", "localhost_12916" ],
+    "myDB_2" : [ "localhost_12913", "localhost_12917", "localhost_12918" ],
+    "myDB_3" : [ "localhost_12915", "localhost_12917", "localhost_12918" ],
+    "myDB_4" : [ "localhost_12916", "localhost_12917", "localhost_12918" ],
+    "myDB_5" : [ "localhost_12914", "localhost_12915", "localhost_12913" ]
+  },
+  "simpleFields" : {
+    "IDEAL_STATE_MODE" : "AUTO",
+    "REBALANCE_MODE" : "SEMI_AUTO",
+    "NUM_PARTITIONS" : "6",
+    "REPLICAS" : "3",
+    "STATE_MODEL_DEF_REF" : "MasterSlave",
+    "STATE_MODEL_FACTORY_NAME" : "DEFAULT"
+  }
+}
+
+ExternalView for myDB:
+{
+  "id" : "myDB",
+  "mapFields" : {
+    "myDB_0" : {
+      "localhost_12913" : "SLAVE",
+      "localhost_12914" : "SLAVE",
+      "localhost_12917" : "MASTER"
+    },
+    "myDB_1" : {
+      "localhost_12916" : "SLAVE",
+      "localhost_12917" : "SLAVE",
+      "localhost_12918" : "MASTER"
+    },
+    "myDB_2" : {
+      "localhost_12913" : "MASTER",
+      "localhost_12917" : "SLAVE",
+      "localhost_12918" : "SLAVE"
+    },
+    "myDB_3" : {
+      "localhost_12915" : "MASTER",
+      "localhost_12917" : "SLAVE",
+      "localhost_12918" : "SLAVE"
+    },
+    "myDB_4" : {
+      "localhost_12916" : "MASTER",
+      "localhost_12917" : "SLAVE",
+      "localhost_12918" : "SLAVE"
+    },
+    "myDB_5" : {
+      "localhost_12913" : "SLAVE",
+      "localhost_12914" : "MASTER",
+      "localhost_12915" : "SLAVE"
+    }
+  },
+  "listFields" : {
+  },
+  "simpleFields" : {
+    "BUCKET_SIZE" : "0"
+  }
+}
+
+
+

Mission accomplished. The partitions are nicely balanced.

+
+
+

How about Failover?

+

Building a fault tolerant system isn't trivial, but with Helix, it's easy. Helix detects a failed instance, and triggers mastership transfer automatically.

+

First, let’s fail an instance. In this example, we'll kill localhost:12918 to simulate a failure.

+

We lost localhost:12918, so myDB_1 lost its MASTER. Helix can fix that, it will transfer mastership to a healthy node that is currently a SLAVE, say localhost:12197. Helix balances the load as best as it can, given there are 6 partitions on 5 nodes. Let's see:

+
+
./helix-admin.sh --zkSvr localhost:2199 --listResourceInfo MYCLUSTER myDB
+
+IdealState for myDB:
+{
+  "id" : "myDB",
+  "mapFields" : {
+    "myDB_0" : {
+      "localhost_12913" : "SLAVE",
+      "localhost_12914" : "SLAVE",
+      "localhost_12917" : "MASTER"
+    },
+    "myDB_1" : {
+      "localhost_12916" : "SLAVE",
+      "localhost_12917" : "SLAVE",
+      "localhost_12918" : "MASTER"
+    },
+    "myDB_2" : {
+      "localhost_12913" : "MASTER",
+      "localhost_12917" : "SLAVE",
+      "localhost_12918" : "SLAVE"
+    },
+    "myDB_3" : {
+      "localhost_12915" : "MASTER",
+      "localhost_12917" : "SLAVE",
+      "localhost_12918" : "SLAVE"
+    },
+    "myDB_4" : {
+      "localhost_12916" : "MASTER",
+      "localhost_12917" : "SLAVE",
+      "localhost_12918" : "SLAVE"
+    },
+    "myDB_5" : {
+      "localhost_12913" : "SLAVE",
+      "localhost_12914" : "MASTER",
+      "localhost_12915" : "SLAVE"
+    }
+  },
+  "listFields" : {
+    "myDB_0" : [ "localhost_12917", "localhost_12913", "localhost_12914" ],
+    "myDB_1" : [ "localhost_12918", "localhost_12917", "localhost_12916" ],
+    "myDB_2" : [ "localhost_12913", "localhost_12918", "localhost_12917" ],
+    "myDB_3" : [ "localhost_12915", "localhost_12918", "localhost_12917" ],
+    "myDB_4" : [ "localhost_12916", "localhost_12917", "localhost_12918" ],
+    "myDB_5" : [ "localhost_12914", "localhost_12915", "localhost_12913" ]
+  },
+  "simpleFields" : {
+    "IDEAL_STATE_MODE" : "AUTO",
+    "REBALANCE_MODE" : "SEMI_AUTO",
+    "NUM_PARTITIONS" : "6",
+    "REPLICAS" : "3",
+    "STATE_MODEL_DEF_REF" : "MasterSlave",
+    "STATE_MODEL_FACTORY_NAME" : "DEFAULT"
+  }
+}
+
+ExternalView for myDB:
+{
+  "id" : "myDB",
+  "mapFields" : {
+    "myDB_0" : {
+      "localhost_12913" : "SLAVE",
+      "localhost_12914" : "SLAVE",
+      "localhost_12917" : "MASTER"
+    },
+    "myDB_1" : {
+      "localhost_12916" : "SLAVE",
+      "localhost_12917" : "MASTER"
+    },
+    "myDB_2" : {
+      "localhost_12913" : "MASTER",
+      "localhost_12917" : "SLAVE"
+    },
+    "myDB_3" : {
+      "localhost_12915" : "MASTER",
+      "localhost_12917" : "SLAVE"
+    },
+    "myDB_4" : {
+      "localhost_12916" : "MASTER",
+      "localhost_12917" : "SLAVE"
+    },
+    "myDB_5" : {
+      "localhost_12913" : "SLAVE",
+      "localhost_12914" : "MASTER",
+      "localhost_12915" : "SLAVE"
+    }
+  },
+  "listFields" : {
+  },
+  "simpleFields" : {
+    "BUCKET_SIZE" : "0"
+  }
+}
+
+
+

As we've seen in this Quickstart, Helix takes care of partitioning, load balancing, elasticity, failure detection and recovery.

+
+
+

ZooInspector

+

You can view all of the underlying data by going direct to zookeeper. Use ZooInspector that comes with zookeeper to browse the data. This is a java applet (make sure you have X windows)

+

To start zooinspector run the following command from <zk_install_directory>/contrib/ZooInspector

+
+
java -cp zookeeper-3.3.3-ZooInspector.jar:lib/jtoaster-1.0.4.jar:../../lib/log4j-1.2.15.jar:../../zookeeper-3.3.3.jar org.apache.zookeeper.inspector.ZooInspector
+
+
+
+
+

Next

+

Now that you understand the idea of Helix, read the tutorial to learn how to choose the right state model and constraints for your system, and how to implement it. In many cases, the built-in features meet your requirements. And best of all, Helix is a customizable framework, so you can plug in your own behavior, while retaining the automation provided by Helix.

+
+
+
+
+
+
+ +
+ + + + +
+
+
+

Back to top

+ +

Reflow Maven skin by Andrius Velykis.

+ +
+
Apache Helix, Apache, the Apache feather logo, and the Apache Helix project logos are trademarks of The Apache Software Foundation. + All other marks mentioned may be trademarks or registered trademarks of their respective owners.
+ Privacy Policy +
+
+
+ + + + + + + + + + + + + + + + + + \ No newline at end of file Added: helix/site-content/0.6.7-docs/Tutorial.html URL: http://svn.apache.org/viewvc/helix/site-content/0.6.7-docs/Tutorial.html?rev=1779549&view=auto ============================================================================== --- helix/site-content/0.6.7-docs/Tutorial.html (added) +++ helix/site-content/0.6.7-docs/Tutorial.html Fri Jan 20 01:12:25 2017 @@ -0,0 +1,412 @@ + + + + + + + + Apache Helix - Tutorial + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ +
+ +
+
+ +
+
+
+
+ +

+ +

In this tutorial, we will cover the roles of a Helix-managed cluster, and show the code you need to write to integrate with it. In many cases, there is a simple default behavior that is often appropriate, but you can also customize the behavior.

+

Convention: we first cover the basic approach, which is the easiest to implement. Then, we’ll describe advanced options, which give you more control over the system behavior, but require you to write more code.

+
+
+

Prerequisites

+
    +
  1. Read Concepts/Terminology and Architecture
  2. +
  3. Read the Quickstart guide to learn how Helix models and manages a cluster
  4. +
  5. Install Helix source. See: Quickstart for the steps.
  6. +
+
+ +
+

Preliminaries

+

First, we need to set up the system. Let's walk through the steps in building a distributed system using Helix.

+
+

Start ZooKeeper

+

This starts a zookeeper in standalone mode. For production deployment, see Apache ZooKeeper for instructions.

+
+
./start-standalone-zookeeper.sh 2199 &
+
+
+
+
+

Create a Cluster

+

Creating a cluster will define the cluster in appropriate znodes on ZooKeeper.

+

Using the Java API:

+
+
// Create setup tool instance
+// Note: ZK_ADDRESS is the host:port of Zookeeper
+String ZK_ADDRESS = "localhost:2199";
+admin = new ZKHelixAdmin(ZK_ADDRESS);
+
+String CLUSTER_NAME = "helix-demo";
+//Create cluster namespace in zookeeper
+admin.addCluster(CLUSTER_NAME);
+
+
+

OR

+

Using the command-line interface:

+
+
./helix-admin.sh --zkSvr localhost:2199 --addCluster helix-demo
+
+
+
+
+

Configure the Nodes of the Cluster

+

First we'll add new nodes to the cluster, then configure the nodes in the cluster. Each node in the cluster must be uniquely identifiable. The most commonly used convention is hostname:port.

+
+
String CLUSTER_NAME = "helix-demo";
+int NUM_NODES = 2;
+String hosts[] = new String[]{"localhost","localhost"};
+String ports[] = new String[]{7000,7001};
+for (int i = 0; i < NUM_NODES; i++)
+{
+  InstanceConfig instanceConfig = new InstanceConfig(hosts[i]+ "_" + ports[i]);
+  instanceConfig.setHostName(hosts[i]);
+  instanceConfig.setPort(ports[i]);
+  instanceConfig.setInstanceEnabled(true);
+
+  //Add additional system specific configuration if needed. These can be accessed during the node start up.
+  instanceConfig.getRecord().setSimpleField("key", "value");
+  admin.addInstance(CLUSTER_NAME, instanceConfig);
+}
+
+
+
+
+

Configure the Resource

+

A resource represents the actual task performed by the nodes. It can be a database, index, topic, queue or any other processing entity. A resource can be divided into many sub-parts known as partitions.

+
+
Define the State Model and Constraints
+

For scalability and fault tolerance, each partition can have one or more replicas. The state model allows one to declare the system behavior by first enumerating the various STATES, and the TRANSITIONS between them. A simple model is ONLINE-OFFLINE where ONLINE means the task is active and OFFLINE means it's not active. You can also specify how many replicas must be in each state, these are known as constraints. For example, in a search system, one might need more than one node serving the same index to handle the load.

+

The allowed states:

+
    +
  • MASTER
  • +
  • SLAVE
  • +
  • OFFLINE
  • +
+

The allowed transitions:

+
    +
  • OFFLINE to SLAVE
  • +
  • SLAVE to OFFLINE
  • +
  • SLAVE to MASTER
  • +
  • MASTER to SLAVE
  • +
+

The constraints:

+
    +
  • no more than 1 MASTER per partition
  • +
  • the rest of the replicas should be slaves
  • +
+

The following snippet shows how to declare the state model and constraints for the MASTER-SLAVE model.

+
+
StateModelDefinition.Builder builder = new StateModelDefinition.Builder(STATE_MODEL_NAME);
+
+// Add states and their rank to indicate priority. A lower rank corresponds to a higher priority
+builder.addState(MASTER, 1);
+builder.addState(SLAVE, 2);
+builder.addState(OFFLINE);
+
+// Set the initial state when the node starts
+builder.initialState(OFFLINE);
+
+// Add transitions between the states.
+builder.addTransition(OFFLINE, SLAVE);
+builder.addTransition(SLAVE, OFFLINE);
+builder.addTransition(SLAVE, MASTER);
+builder.addTransition(MASTER, SLAVE);
+
+// set constraints on states
+
+// static constraint: upper bound of 1 MASTER
+builder.upperBound(MASTER, 1);
+
+// dynamic constraint: R means it should be derived based on the replication factor for the cluster
+// this allows a different replication factor for each resource without
+// having to define a new state model
+
+builder.dynamicUpperBound(SLAVE, "R");
+
+StateModelDefinition statemodelDefinition = builder.build();
+admin.addStateModelDef(CLUSTER_NAME, STATE_MODEL_NAME, myStateModel);
+
+
+
+
+
Assigning Partitions to Nodes
+

The final goal of Helix is to ensure that the constraints on the state model are satisfied. Helix does this by assigning a state to a partition (such as MASTER, SLAVE), and placing it on a particular node.

+

There are 3 assignment modes Helix can operate in:

+
    +
  • FULL_AUTO: Helix decides the placement and state of a partition.
  • +
  • SEMI_AUTO: Application decides the placement but Helix decides the state of a partition.
  • +
  • CUSTOMIZED: Application controls the placement and state of a partition.
  • +
+

For more information on the assignment modes, see the Rebalancing Algorithms section of this tutorial.

+
+
String RESOURCE_NAME = "MyDB";
+int NUM_PARTITIONS = 6;
+STATE_MODEL_NAME = "MasterSlave";
+String MODE = "SEMI_AUTO";
+int NUM_REPLICAS = 2;
+
+admin.addResource(CLUSTER_NAME, RESOURCE_NAME, NUM_PARTITIONS, STATE_MODEL_NAME, MODE);
+admin.rebalance(CLUSTER_NAME, RESOURCE_NAME, NUM_REPLICAS);
+
+
+
+
+
+
+
+
+
+
+ +
+ + + + +
+
+
+

Back to top

+ +

Reflow Maven skin by Andrius Velykis.

+ +
+
Apache Helix, Apache, the Apache feather logo, and the Apache Helix project logos are trademarks of The Apache Software Foundation. + All other marks mentioned may be trademarks or registered trademarks of their respective owners.
+ Privacy Policy +
+
+
+ + + + + + + + + + + + + + + + + + \ No newline at end of file Added: helix/site-content/0.6.7-docs/css/bootswatch.css URL: http://svn.apache.org/viewvc/helix/site-content/0.6.7-docs/css/bootswatch.css?rev=1779549&view=auto ============================================================================== --- helix/site-content/0.6.7-docs/css/bootswatch.css (added) +++ helix/site-content/0.6.7-docs/css/bootswatch.css Fri Jan 20 01:12:25 2017 @@ -0,0 +1,70 @@ +body { + padding-top: 80px; + padding-bottom: 20px; +} + +.navbar a > i { + opacity: 0.5; +} + +.navbar a:hover > i { + opacity: 1; +} + +.subhead { + padding-bottom: 0; + margin-bottom: 9px; +} + +.subhead h1 { + font-size: 54px; +} + + +@media (max-width: 480px) { + + .modal { + position: fixed !important; + top: 25% !important; + } +} + + +@media (max-width: 767px) { + + body { + padding-top: 0; + } +} + +/* Portrait tablet to landscape and desktop */ +@media (min-width: 768px) and (max-width: 979px) { + + .thumbnail p { + font-size: 12px; + } + + .thumbnail .btn { + padding: 8px 12px; + font-size: 12px; + } +} + +@media (min-width: 768px) and (max-width: 979px) { + + /* Remove any padding from the body */ + body { + padding-top: 0; + } +} + +@media (max-width: 980px) { + + /* Unfloat brand */ + .navbar-fixed-top .brand { + float: left; + margin-left: 0; + padding-left: 10px; + padding-right: 10px; + } +} \ No newline at end of file Added: helix/site-content/0.6.7-docs/css/docs.css URL: http://svn.apache.org/viewvc/helix/site-content/0.6.7-docs/css/docs.css?rev=1779549&view=auto ============================================================================== --- helix/site-content/0.6.7-docs/css/docs.css (added) +++ helix/site-content/0.6.7-docs/css/docs.css Fri Jan 20 01:12:25 2017 @@ -0,0 +1,150 @@ +/* Add additional stylesheets below +-------------------------------------------------- */ +/* + Bootstrap's documentation styles + Special styles for presenting Bootstrap's documentation and examples +*/ + +/* Body and structure +-------------------------------------------------- */ + +body { + position: relative; + padding-top: 40px; +} + +/* Code in headings */ +h3 code { + font-size: 14px; + font-weight: normal; +} + +/* Jumbotrons +-------------------------------------------------- */ +.jumbotron { + position: relative; + padding: 40px 0; +} +.jumbotron h1 { + font-size: 80px; + font-weight: bold; + letter-spacing: -1px; + line-height: 1; +} +.jumbotron p { + font-size: 24px; + font-weight: 300; + line-height: 30px; + margin-bottom: 30px; +} +.jumbotron .btn-large { + font-size: 20px; + font-weight: normal; + padding: 14px 24px; + margin-right: 10px; + -webkit-border-radius: 6px; + -moz-border-radius: 6px; + border-radius: 6px; +} +.jumbotron .btn-large small { + font-size: 14px; +} + + +/* Specific jumbotrons +------------------------- */ +/* supporting docs pages */ +.subhead { + padding-bottom: 0; + margin-bottom: 9px; +} +.subhead h1 { + font-size: 54px; +} + +/* Responsive Docs +-------------------------------------------------- */ +@media (max-width: 480px) { + + /* Reduce padding above jumbotron */ + body { + padding-top: 70px; + } + + /* Adjust the jumbotron */ + .jumbotron h1, + .jumbotron p { + text-align: center; + margin-right: 0; + } + .jumbotron h1 { + font-size: 45px; + margin-right: 0; + } + .jumbotron p { + margin-right: 0; + margin-left: 0; + font-size: 18px; + line-height: 24px; + } + .jumbotron .btn { + display: block; + font-size: 18px; + padding: 10px 14px; + margin: 0 auto 10px; + } + +} + + +@media (max-width: 768px) { + + /* Remove any padding from the body */ + body { + padding-top: 0; + } + + /* Jumbotron buttons */ + .jumbotron .btn { + margin-bottom: 10px; + } +} + + +@media (min-width: 480px) and (max-width: 768px) { + + /* Scale down the jumbotron content */ + .jumbotron h1 { + font-size: 54px; + } + .jumbotron p { + margin-right: 0; + margin-left: 0; + } +} + + +@media (min-width: 768px) and (max-width: 980px) { + + /* Remove any padding from the body */ + body { + padding-top: 0; + } + + /* Scale down the jumbotron content */ + .jumbotron h1 { + font-size: 72px; + } +} + + +@media (max-width: 980px) { + + /* Unfloat brand */ + .navbar-fixed-top .brand { + float: left; + margin-left: 0; + padding-left: 10px; + padding-right: 10px; + } +} \ No newline at end of file Added: helix/site-content/0.6.7-docs/css/lightbox.css URL: http://svn.apache.org/viewvc/helix/site-content/0.6.7-docs/css/lightbox.css?rev=1779549&view=auto ============================================================================== --- helix/site-content/0.6.7-docs/css/lightbox.css (added) +++ helix/site-content/0.6.7-docs/css/lightbox.css Fri Jan 20 01:12:25 2017 @@ -0,0 +1,181 @@ +/* line 6, ../sass/lightbox.sass */ +#lightboxOverlay { + position: absolute; + top: 0; + left: 0; + z-index: 9999; + background-color: black; + filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=85); + opacity: 0.85; + display: none; +} + +/* line 15, ../sass/lightbox.sass */ +#lightbox { + position: absolute; + left: 0; + width: 100%; + z-index: 10000; + text-align: center; + line-height: 0; + font-family: "lucida grande", tahoma, verdana, arial, sans-serif; + font-weight: normal; +} +/* line 24, ../sass/lightbox.sass */ +#lightbox img { + width: auto; + height: auto; +} +/* line 27, ../sass/lightbox.sass */ +#lightbox a img { + border: none; +} + +/* line 30, ../sass/lightbox.sass */ +.lb-outerContainer { + position: relative; + background-color: white; + *zoom: 1; + width: 250px; + height: 250px; + margin: 0 auto; + -webkit-border-radius: 4px; + -moz-border-radius: 4px; + -ms-border-radius: 4px; + -o-border-radius: 4px; + border-radius: 4px; +} +/* line 38, ../../../../.rvm/gems/ruby-1.9.2-p290/gems/compass-0.12.1/frameworks/compass/stylesheets/compass/utilities/general/_clearfix.scss */ +.lb-outerContainer:after { + content: ""; + display: table; + clear: both; +} + +/* line 39, ../sass/lightbox.sass */ +.lb-container { + padding: 10px; +} + +/* line 42, ../sass/lightbox.sass */ +.lb-loader { + position: absolute; + top: 40%; + left: 0%; + height: 25%; + width: 100%; + text-align: center; + line-height: 0; +} + +/* line 51, ../sass/lightbox.sass */ +.lb-nav { + position: absolute; + top: 0; + left: 0; + height: 100%; + width: 100%; + z-index: 10; +} + +/* line 59, ../sass/lightbox.sass */ +.lb-container > .nav { + left: 0; +} + +/* line 62, ../sass/lightbox.sass */ +.lb-nav a { + outline: none; +} + +/* line 65, ../sass/lightbox.sass */ +.lb-prev, .lb-next { + width: 49%; + height: 100%; + background-image: url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"); + /* Trick IE into showing hover */ + display: block; +} + +/* line 72, ../sass/lightbox.sass */ +.lb-prev { + left: 0; + float: left; +} + +/* line 76, ../sass/lightbox.sass */ +.lb-next { + right: 0; + float: right; +} + +/* line 81, ../sass/lightbox.sass */ +.lb-prev:hover { + background: url(../images/prev.png) left 48% no-repeat; +} + +/* line 85, ../sass/lightbox.sass */ +.lb-next:hover { + background: url(../images/next.png) right 48% no-repeat; +} + +/* line 88, ../sass/lightbox.sass */ +.lb-dataContainer { + margin: 0 auto; + padding-top: 5px; + *zoom: 1; + width: 100%; + -moz-border-radius-bottomleft: 4px; + -webkit-border-bottom-left-radius: 4px; + -ms-border-bottom-left-radius: 4px; + -o-border-bottom-left-radius: 4px; + border-bottom-left-radius: 4px; + -moz-border-radius-bottomright: 4px; + -webkit-border-bottom-right-radius: 4px; + -ms-border-bottom-right-radius: 4px; + -o-border-bottom-right-radius: 4px; + border-bottom-right-radius: 4px; +} +/* line 38, ../../../../.rvm/gems/ruby-1.9.2-p290/gems/compass-0.12.1/frameworks/compass/stylesheets/compass/utilities/general/_clearfix.scss */ +.lb-dataContainer:after { + content: ""; + display: table; + clear: both; +} + +/* line 95, ../sass/lightbox.sass */ +.lb-data { + padding: 0 10px; + color: #bbbbbb; +} +/* line 98, ../sass/lightbox.sass */ +.lb-data .lb-details { + width: 85%; + float: left; + text-align: left; + line-height: 1.1em; +} +/* line 103, ../sass/lightbox.sass */ +.lb-data .lb-caption { + font-size: 13px; + font-weight: bold; + line-height: 1em; +} +/* line 107, ../sass/lightbox.sass */ +.lb-data .lb-number { + display: block; + clear: left; + padding-bottom: 1em; + font-size: 11px; +} +/* line 112, ../sass/lightbox.sass */ +.lb-data .lb-close { + width: 35px; + float: right; + padding-bottom: 0.7em; + outline: none; +} +/* line 117, ../sass/lightbox.sass */ +.lb-data .lb-close:hover { + cursor: pointer; +} \ No newline at end of file Added: helix/site-content/0.6.7-docs/css/print.css URL: http://svn.apache.org/viewvc/helix/site-content/0.6.7-docs/css/print.css?rev=1779549&view=auto ============================================================================== --- helix/site-content/0.6.7-docs/css/print.css (added) +++ helix/site-content/0.6.7-docs/css/print.css Fri Jan 20 01:12:25 2017 @@ -0,0 +1,80 @@ +.navbar, +.breadcrumb, +.toc-separator +#toc-bar, +#toc-sidebar, +footer, +.subfooter { + display: none !important; +} + +body { + padding-top: 0px !important; +} + +/* CSS below taken from HTML5 Boilerplate */ +* { + background: transparent !important; + color: #000 !important; /* Black prints faster: h5bp.com/s */ + box-shadow:none !important; + text-shadow: none !important; +} + +a, +a:visited { + text-decoration: underline; +} + +a[href]:after { + content: " (" attr(href) ")"; +} + +abbr[title]:after { + content: " (" attr(title) ")"; +} + +/* + * Don't show links for images, or javascript/internal links, or header links + */ + +header a:after, +.ir a:after, +a[href^="javascript:"]:after, +a[href^="#"]:after { + content: "" !important; +} + +pre, +blockquote { + border: 1px solid #999; + page-break-inside: avoid; +} + +thead { + display: table-header-group; /* h5bp.com/t */ +} + +tr, +img { + page-break-inside: avoid; +} + +img { + max-width: 100% !important; +} + +@page { + margin: 0.5cm; +} + +p, +h2, +h3 { + orphans: 3; + widows: 3; +} + +h2, +h3 { + page-break-after: avoid; +} \ No newline at end of file Added: helix/site-content/0.6.7-docs/css/reflow-skin.css URL: http://svn.apache.org/viewvc/helix/site-content/0.6.7-docs/css/reflow-skin.css?rev=1779549&view=auto ============================================================================== --- helix/site-content/0.6.7-docs/css/reflow-skin.css (added) +++ helix/site-content/0.6.7-docs/css/reflow-skin.css Fri Jan 20 01:12:25 2017 @@ -0,0 +1,104 @@ +/* Jumps to in-page links (e.g. page.html#foo) do not honor fixed navbar. + Use pseudo element to move them down. + Taken from http://nicolasgallagher.com/jump-links-and-viewport-positioning/demo/#method-B + */ +h1[id]:before, +h2[id]:before, +h3[id]:before, +h4[id]:before, +h5[id]:before, +h6[id]:before, +a[name]:before { + display:block; + content:""; + height:90px; + margin:-90px 0 0; +} + + +/* Fixed subnav support: */ + +/* Fixed subnav on scroll, but only for 980px and up (sorry IE!) */ +@media (min-width: 980px) { + .navbar.affix { + position: fixed; + top: 40px; + right: 0; + left: 0; + z-index: 1020; /* 10 less than .navbar-fixed to prevent any overlap */ + margin-bottom: 0; + } + + .navbar.affix .navbar-inner { + border-width: 0 0 1px; + padding-right: 0; + padding-left: 0; + -webkit-border-radius: 0; + -moz-border-radius: 0; + border-radius: 0; + -webkit-box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.1), 0 1px 10px rgba(0, 0, 0, 0.1); + -moz-box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.1), 0 1px 10px rgba(0, 0, 0, 0.1); + box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.1), 0 1px 10px rgba(0, 0, 0, 0.1); + } + + .navbar.affix .container { + width: 940px; + } +} + +/* Other screen sizes navbar container width */ +@media (min-width: 1200px) { + .navbar.affix .container { + width: 1170px; + } +} +@media (min-width: 768px) and (max-width: 979px) { + .navbar.affix .container { + width: 724px; + } +} +@media (max-width: 767px) { + .navbar.affix { + margin-right: -20px; + margin-left: -20px; + } +} +@media (max-width: 979px) { + .navbar.affix { + position: static; + margin-bottom: 20px; + } + .navbar.affix .navbar-inner { + padding: 5px; + } +} + +/* Fix for header links - do not color/underline them */ +#banner a { + color: inherit; + text-decoration: inherit; +} + + +/* Footer */ + +footer.well { + padding: 50px 0; + margin-top: 70px; + margin-bottom: 0; + -webkit-border-radius: 0; + -moz-border-radius: 0; + border-radius: 0; + border-right: 0; + border-left: 0; + font-size: 90%; +} + +footer.well p, +.subfooter p { + margin-bottom: 0; +} + +.subfooter { + padding: 30px 0; +} \ No newline at end of file Added: helix/site-content/0.6.7-docs/css/site.css URL: http://svn.apache.org/viewvc/helix/site-content/0.6.7-docs/css/site.css?rev=1779549&view=auto ============================================================================== --- helix/site-content/0.6.7-docs/css/site.css (added) +++ helix/site-content/0.6.7-docs/css/site.css Fri Jan 20 01:12:25 2017 @@ -0,0 +1 @@ +/* You can override this file with your own styles */ \ No newline at end of file