blob: 1adb9214f13f8b97af79848f82c55d8e7281d35a [file] [log] [blame]
Madan Jampani25461112015-02-17 14:17:29 -08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Madan Jampani09342702015-02-05 23:32:40 -080017package org.onosproject.store.consistent.impl;
18
19import java.util.Map;
20
21/**
22 * A simple Partitioner that uses the table name hash to
23 * pick a partition.
24 * <p>
25 * This class uses a md5 hash based hashing scheme for hashing the table name to
26 * a partition. This partitioner maps all keys for a table to the same database
27 * partition.
28 */
29public class SimpleTableHashPartitioner extends DatabasePartitioner {
30
31 public SimpleTableHashPartitioner(Map<String, Database> partitionMap) {
32 super(partitionMap);
33 }
34
35 @Override
36 public Database getPartition(String tableName, String key) {
37 return sortedPartitions[hash(tableName) % sortedPartitions.length];
38 }
39}