Esempio n. 1
0
    def verify_final_index_state(self, state_transitions):
        # print "Verifying final view state"
        doc_count = common.set_doc_count(self._params)
        (resp, view_result) = common.query(self._params, "mapview")

        # print "Final view result (%d rows):  %s" % \
        #    (len(view_result["rows"]), json.dumps(view_result, sort_keys = True, indent = 4))

        self.assertEqual(view_result["total_rows"], doc_count,
                         "Query returned %d total_rows" % doc_count)
        self.assertEqual(len(view_result["rows"]), doc_count,
                         "Query returned %d rows" % doc_count)

        self.assertEqual(view_result["rows"][0]["key"], 1, "First key is 1")
        self.assertEqual(view_result["rows"][-1]["key"], doc_count, "Last key is %d" % doc_count)
        common.test_keys_sorted(view_result)

        # print "Verifying group info"
        info = common.get_set_view_info(self._params)
        # print "Final group info:  %s" % json.dumps(info, sort_keys = True, indent = 4)
        self.assertEqual(
            info["active_partitions"],
            [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
            "right active partitions list"
            )
        self.assertEqual(info["passive_partitions"], [], "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [], "right cleanup partitions list")

        for i in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]:
            expected_seq = common.partition_update_seq(self._params, i)
            self.assertEqual(info["update_seqs"][str(i)], expected_seq,
                             "right update seq number (%d) for partition %d" % (expected_seq, i + 1))

        return info["stats"]
Esempio n. 2
0
    def do_test_set_active_during_compaction(self):
        # print "Triggering view compaction"
        common.compact_set_view(self._params, False)

        # print "Marking partitions 4, 5 and 6 as active while compaction is running"
        common.set_partition_states(self._params, active = [3, 4, 5])

        # print "Adding new partitions 7 and 8 with active state while compaction is running"
        common.set_partition_states(self._params, active = [6, 7])

        info = common.get_set_view_info(self._params)
        self.assertEqual(info["active_partitions"], [0, 1, 2, 3, 4, 5, 6, 7], "right active partitions list")
        self.assertEqual(info["passive_partitions"], [], "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [], "right cleanup partitions list")

        # print "Querying map view while compaction is running"
        (map_resp, map_view_result) = common.query(self._params, "mapview1", {"limit": "10"})

        self.assertEqual(len(map_view_result["rows"]), 10, "Query returned 10 rows")
        common.test_keys_sorted(map_view_result)

        # print "Waiting for compaction to finish"
        compaction_was_running = (common.wait_set_view_compaction_complete(self._params) > 0)
        self.assertTrue(compaction_was_running, "Compaction was running when the view update was triggered")

        # print "Verifying group info"
        info = common.get_set_view_info(self._params)
        self.assertEqual(info["active_partitions"], [0, 1, 2, 3, 4, 5, 6, 7], "right active partitions list")
        self.assertEqual(info["passive_partitions"], [], "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [], "right cleanup partitions list")

        # print "Querying map view again"
        doc_count = common.set_doc_count(self._params, [0, 1, 2, 3, 4, 5, 6, 7])
        (map_resp, map_view_result) = common.query(self._params, "mapview1")

        self.assertEqual(map_view_result["total_rows"], doc_count,
                         "Query returned %d total_rows" % doc_count)
        self.assertEqual(len(map_view_result["rows"]), doc_count,
                         "Query returned %d rows" % doc_count)

        common.test_keys_sorted(map_view_result)

        # print "Verifying group info"
        info = common.get_set_view_info(self._params)
        self.assertEqual(info["active_partitions"], [0, 1, 2, 3, 4, 5, 6, 7], "right active partitions list")
        self.assertEqual(info["passive_partitions"], [], "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [], "right cleanup partitions list")
        for i in [0, 1, 2, 3, 4, 5, 6, 7]:
            self.assertTrue(str(i) in info["update_seqs"], "%d in info.update_seqs" % i)
            expected_seq = common.partition_update_seq(self._params, i)
            self.assertEqual(info["update_seqs"][str(i)], expected_seq,
                             "info.update_seqs[%d] is %d" % (i, expected_seq))
Esempio n. 3
0
    def verify_final_index_state(self, state_transitions):
        # print "Verifying final view state"
        doc_count = common.set_doc_count(self._params)
        (resp, view_result) = common.query(self._params, "mapview")

        # print "Final view result (%d rows):  %s" % \
        #    (len(view_result["rows"]), json.dumps(view_result, sort_keys = True, indent = 4))

        self.assertEqual(view_result["total_rows"], doc_count,
                         "Query returned %d total_rows" % doc_count)
        self.assertEqual(len(view_result["rows"]), doc_count,
                         "Query returned %d rows" % doc_count)

        self.assertEqual(view_result["rows"][0]["key"], 1, "First key is 1")
        self.assertEqual(view_result["rows"][-1]["key"], doc_count,
                         "Last key is %d" % doc_count)
        common.test_keys_sorted(view_result)

        # print "Verifying group info"
        info = common.get_set_view_info(self._params)
        # print "Final group info:  %s" % json.dumps(info, sort_keys = True, indent = 4)
        self.assertEqual(
            info["active_partitions"],
            [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
            "right active partitions list")
        self.assertEqual(info["passive_partitions"], [],
                         "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [],
                         "right cleanup partitions list")

        for i in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]:
            expected_seq = common.partition_update_seq(self._params, i)
            self.assertEqual(
                info["update_seqs"][str(i)], expected_seq,
                "right update seq number (%d) for partition %d" %
                (expected_seq, i + 1))

        return info["stats"]
Esempio n. 4
0
    def test_updates(self):
        total_doc_count = common.set_doc_count(self._params,
                                               [0, 1, 2, 3, 4, 5, 6, 7])
        # print "Querying view in steady state with ?stale=update_after"
        (resp, view_result) = common.query(self._params, "mapview",
                                           {"stale": "update_after"})

        self.assertEqual(len(view_result["rows"]), 0, "Received empty row set")
        self.assertEqual(view_result["total_rows"], 0,
                         "Received empty row set")

        # print "Adding partitions 7 and 8 as active while updater is running"
        common.set_partition_states(self._params, active=[6, 7])

        # print "Verifying group info"
        info = common.get_set_view_info(self._params)
        self.assertEqual(info["active_partitions"], [0, 1, 2, 3, 4, 5, 6, 7],
                         "right active partitions list")
        self.assertEqual(info["passive_partitions"], [],
                         "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [],
                         "right cleanup partitions list")

        # print "Waiting for updater to finish"
        count = 0
        while True:
            info = common.get_set_view_info(self._params)
            if info["updater_running"]:
                count += 1
            else:
                break

        self.assertTrue(
            count > 0,
            "Updater was running when partitions 7 and 8 were added as active")

        # print "Verifying group info"
        info = common.get_set_view_info(self._params)
        self.assertEqual(info["active_partitions"], [0, 1, 2, 3, 4, 5, 6, 7],
                         "right active partitions list")
        self.assertEqual(info["passive_partitions"], [],
                         "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [],
                         "right cleanup partitions list")
        for i in [0, 1, 2, 3, 4, 5]:
            expected_seq = common.partition_update_seq(self._params, i)
            self.assertEqual(
                info["update_seqs"][str(i)], expected_seq,
                "right update seq number (%d) for partition %d" %
                (expected_seq, i + 1))

        # print "Querying view again (steady state)"
        (resp, view_result) = common.query(self._params, "mapview")

        self.assertEqual(len(view_result["rows"]), total_doc_count,
                         "number of received rows is %d" % total_doc_count)
        self.assertEqual(view_result["total_rows"], total_doc_count,
                         "total_rows is %d" % total_doc_count)
        common.test_keys_sorted(view_result)

        # print "Adding 1 new document to each partition"
        new_docs = []
        for i in [0, 1, 2, 3, 4, 5, 6, 7]:
            server = self._params["server"]
            db = self._params["server"][self._params["setname"] + "/" + str(i)]
            value = total_doc_count + i + 1
            new_doc = {
                "_id": str(value),
                "integer": value,
                "string": str(value)
            }
            new_docs.append(new_doc)
            db.save(new_doc)

        new_total_doc_count = common.set_doc_count(self._params,
                                                   [0, 1, 2, 3, 4, 5, 6, 7])
        self.assertEqual(new_total_doc_count,
                         (total_doc_count + len(new_docs)),
                         "8 documents were added")
        total_doc_count = new_total_doc_count

        # print "Querying view again (steady state)"
        (resp, view_result) = common.query(self._params, "mapview")

        self.assertEqual(len(view_result["rows"]), total_doc_count,
                         "number of received rows is %d" % total_doc_count)
        self.assertEqual(view_result["total_rows"], total_doc_count,
                         "total_rows is %d" % total_doc_count)
        common.test_keys_sorted(view_result)

        i = len(new_docs) - 1
        j = len(view_result["rows"]) - 1
        while i >= 0:
            self.assertEqual(
                view_result["rows"][j]["key"], new_docs[i]["integer"],
                "new document %s in view result set" % new_docs[i]["_id"])
            self.assertEqual(
                view_result["rows"][j]["id"], new_docs[i]["_id"],
                "new document %s in view result set" % new_docs[i]["_id"])
            i -= 1
            j -= 1

        # print "Deleting the documents that were added before"
        i = 0
        for doc in new_docs:
            db = self._params["setname"] + "/" + str(i)
            common.delete_doc(self._params, db, doc["_id"])
            i = (i + 1) % self._params["nparts"]

        new_total_doc_count = common.set_doc_count(self._params,
                                                   [0, 1, 2, 3, 4, 5, 6, 7])
        self.assertEqual(new_total_doc_count,
                         (total_doc_count - len(new_docs)),
                         "8 documents were deleted")

        # print "Querying view again (steady state)"
        (resp, view_result) = common.query(self._params, "mapview")

        self.assertEqual(len(view_result["rows"]), new_total_doc_count,
                         "number of received rows is %d" % new_total_doc_count)
        self.assertEqual(view_result["total_rows"], new_total_doc_count,
                         "total_rows is %d" % new_total_doc_count)
        common.test_keys_sorted(view_result)

        all_ids = {}
        all_keys = {}
        for row in view_result["rows"]:
            all_ids[row["id"]] = True
            all_keys[row["key"]] = True

        for doc in new_docs:
            self.assertFalse(doc["_id"] in all_ids,
                             "deleted doc %s not in view results anymore")
            self.assertFalse(doc["integer"] in all_keys,
                             "deleted doc %s not in view results anymore")
Esempio n. 5
0
    def test_update_cleanup(self):
        # print "Triggering initial view update"
        t0 = time.time()
        (resp, view_result) = common.query(self._params, "mapview",
                                           {"limit": "1"})
        # print "Update took %.2f seconds" % (time.time() - t0)

        # print "Verifying group info"

        info = common.get_set_view_info(self._params)
        stats = info["stats"]

        self.assertEqual(info["active_partitions"], [0, 1, 2, 3],
                         "right active partitions list")
        self.assertEqual(info["passive_partitions"], [],
                         "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [],
                         "right cleanup partitions list")
        self.assertEqual(stats["full_updates"], 1, "1 full update done so far")
        self.assertEqual(stats["stopped_updates"], 0,
                         "no updater interruptions so far")
        self.assertEqual(stats["cleanups"], 0, "0 cleanups done")
        self.assertEqual(stats["cleanup_interruptions"], 0,
                         "no cleanup interruptions so far")

        # print "Adding new partitions 5, 6, 7 and 8 and marking partitions 1 and 4 for cleanup"
        common.set_partition_states(self._params,
                                    active=[4, 5, 6, 7],
                                    cleanup=[0, 3])

        # print "Querying view (should trigger update + cleanup)"
        t0 = time.time()
        (resp, view_result) = common.query(self._params, "mapview")
        t1 = time.time()

        # print "Verifying query results"

        expected_total = common.set_doc_count(self._params, [1, 2, 4, 5, 6, 7])
        self.assertEqual(view_result["total_rows"], expected_total,
                         "total rows is %d" % expected_total)
        self.assertEqual(len(view_result["rows"]), expected_total,
                         "got %d tows" % expected_total)
        common.test_keys_sorted(view_result)

        all_keys = {}
        for r in view_result["rows"]:
            all_keys[r["key"]] = True

        for key in xrange(1, self._params["ndocs"], self._params["nparts"]):
            self.assertFalse(
                key in all_keys,
                "Key %d (partition 1) not in query result after update+cleanup"
                % key)
        for key in xrange(2, self._params["ndocs"], self._params["nparts"]):
            self.assertTrue(
                key in all_keys,
                "Key %d (partition 2) in query result after update+cleanup" %
                key)
        for key in xrange(3, self._params["ndocs"], self._params["nparts"]):
            self.assertTrue(
                key in all_keys,
                "Key %d (partition 3) in query result after update+cleanup" %
                key)
        for key in xrange(4, self._params["ndocs"], self._params["nparts"]):
            self.assertFalse(
                key in all_keys,
                "Key %d (partition 4) not in query result after update+cleanup"
                % key)
        for key in xrange(5, self._params["ndocs"], self._params["nparts"]):
            self.assertTrue(
                key in all_keys,
                "Key %d (partition 5) in query result after update+cleanup" %
                key)
        for key in xrange(6, self._params["ndocs"], self._params["nparts"]):
            self.assertTrue(
                key in all_keys,
                "Key %d (partition 6) in query result after update+cleanup" %
                key)
        for key in xrange(7, self._params["ndocs"], self._params["nparts"]):
            self.assertTrue(
                key in all_keys,
                "Key %d (partition 7) in query result after update+cleanup" %
                key)
        for key in xrange(8, self._params["ndocs"], self._params["nparts"]):
            self.assertTrue(
                key in all_keys,
                "Key %d (partition 8) in query result after update+cleanup" %
                key)

        # print "Verifying group info"

        info = common.get_set_view_info(self._params)
        stats = info["stats"]

        self.assertEqual(info["active_partitions"], [1, 2, 4, 5, 6, 7],
                         "right active partitions list")
        self.assertEqual(info["passive_partitions"], [],
                         "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [],
                         "right cleanup partitions list")
        self.assertEqual(stats["full_updates"], 2,
                         "2 full updates done so far")
        self.assertEqual(stats["stopped_updates"], 0,
                         "no updater interruptions so far")
        self.assertEqual(stats["cleanups"], 1, "1 full cleanup done")
        self.assertEqual(stats["cleanup_interruptions"], 1,
                         "1 cleanup interruption done")

        for i in info["active_partitions"]:
            expected_seq = common.partition_update_seq(self._params, i)
            self.assertTrue(
                str(i) in info["update_seqs"],
                "partition %d in info.update_seqs" % (i + 1))
            self.assertEqual(info["update_seqs"][str(i)], expected_seq,
                             "right seq in info.update_seqs[%d]" % i)
Esempio n. 6
0
    def test_updates(self):
        total_doc_count = common.set_doc_count(self._params, [0, 1, 2, 3, 4, 5, 6, 7])
        # print "Querying view in steady state with ?stale=update_after"
        (resp, view_result) = common.query(self._params, "mapview", {"stale": "update_after"})

        self.assertEqual(len(view_result["rows"]), 0, "Received empty row set")
        self.assertEqual(view_result["total_rows"], 0, "Received empty row set")

        # print "Adding partitions 7 and 8 as active while updater is running"
        common.set_partition_states(self._params, active = [6, 7])

        # print "Verifying group info"
        info = common.get_set_view_info(self._params)
        self.assertEqual(info["active_partitions"], [0, 1, 2, 3, 4, 5, 6, 7], "right active partitions list")
        self.assertEqual(info["passive_partitions"], [], "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [], "right cleanup partitions list")

        # print "Waiting for updater to finish"
        count = 0
        while True:
            info = common.get_set_view_info(self._params)
            if info["updater_running"]:
                count += 1
            else:
                break

        self.assertTrue(count > 0, "Updater was running when partitions 7 and 8 were added as active")

        # print "Verifying group info"
        info = common.get_set_view_info(self._params)
        self.assertEqual(info["active_partitions"], [0, 1, 2, 3, 4, 5, 6, 7], "right active partitions list")
        self.assertEqual(info["passive_partitions"], [], "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [], "right cleanup partitions list")
        for i in [0, 1, 2, 3, 4, 5]:
            expected_seq = common.partition_update_seq(self._params, i)
            self.assertEqual(info["update_seqs"][str(i)], expected_seq,
                             "right update seq number (%d) for partition %d" % (expected_seq, i + 1))

        # print "Querying view again (steady state)"
        (resp, view_result) = common.query(self._params, "mapview")

        self.assertEqual(len(view_result["rows"]), total_doc_count, "number of received rows is %d" % total_doc_count)
        self.assertEqual(view_result["total_rows"], total_doc_count, "total_rows is %d" % total_doc_count)
        common.test_keys_sorted(view_result)

        # print "Adding 1 new document to each partition"
        new_docs = []
        for i in [0, 1, 2, 3, 4, 5, 6, 7]:
            server = self._params["server"]
            db = self._params["server"][self._params["setname"] + "/" + str(i)]
            value = total_doc_count + i + 1
            new_doc = {
                "_id": str(value),
                "integer": value,
                "string": str(value)
                }
            new_docs.append(new_doc)
            db.save(new_doc)

        new_total_doc_count = common.set_doc_count(self._params, [0, 1, 2, 3, 4, 5, 6, 7])
        self.assertEqual(new_total_doc_count, (total_doc_count + len(new_docs)), "8 documents were added")
        total_doc_count = new_total_doc_count

        # print "Querying view again (steady state)"
        (resp, view_result) = common.query(self._params, "mapview")

        self.assertEqual(len(view_result["rows"]), total_doc_count, "number of received rows is %d" % total_doc_count)
        self.assertEqual(view_result["total_rows"], total_doc_count, "total_rows is %d" % total_doc_count)
        common.test_keys_sorted(view_result)

        i = len(new_docs) - 1
        j = len(view_result["rows"]) - 1
        while i >= 0:
            self.assertEqual(view_result["rows"][j]["key"], new_docs[i]["integer"],
                             "new document %s in view result set" % new_docs[i]["_id"])
            self.assertEqual(view_result["rows"][j]["id"], new_docs[i]["_id"],
                             "new document %s in view result set" % new_docs[i]["_id"])
            i -= 1
            j -= 1

        # print "Deleting the documents that were added before"
        i = 0
        for doc in new_docs:
            db = self._params["setname"] + "/" + str(i)
            common.delete_doc(self._params, db, doc["_id"])
            i = (i + 1) % self._params["nparts"]

        new_total_doc_count = common.set_doc_count(self._params, [0, 1, 2, 3, 4, 5, 6, 7])
        self.assertEqual(new_total_doc_count, (total_doc_count - len(new_docs)), "8 documents were deleted")

        # print "Querying view again (steady state)"
        (resp, view_result) = common.query(self._params, "mapview")

        self.assertEqual(len(view_result["rows"]), new_total_doc_count,
                         "number of received rows is %d" % new_total_doc_count)
        self.assertEqual(view_result["total_rows"], new_total_doc_count,
                         "total_rows is %d" % new_total_doc_count)
        common.test_keys_sorted(view_result)

        all_ids = {}
        all_keys = {}
        for row in view_result["rows"]:
            all_ids[row["id"]] = True
            all_keys[row["key"]] = True

        for doc in new_docs:
            self.assertFalse(doc["_id"] in all_ids, "deleted doc %s not in view results anymore")
            self.assertFalse(doc["integer"] in all_keys, "deleted doc %s not in view results anymore")
Esempio n. 7
0
    def test_many_partitions(self):
        total_doc_count = common.set_doc_count(self._params,
                                               range(self._params["nparts"]))

        # print "Querying view"
        (resp, view_result) = common.query(self._params, "mapview")

        self.assertEqual(len(view_result["rows"]), total_doc_count,
                         "number of received rows is %d" % total_doc_count)
        self.assertEqual(view_result["total_rows"], total_doc_count,
                         "total_rows is %d" % total_doc_count)
        common.test_keys_sorted(view_result)

        # print "Verifying group info"
        info = common.get_set_view_info(self._params)
        self.assertEqual(info["active_partitions"],
                         range(self._params["nparts"]),
                         "right active partitions list")
        self.assertEqual(info["passive_partitions"], [],
                         "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [],
                         "right cleanup partitions list")
        for i in xrange(self._params["nparts"]):
            expected_seq = common.partition_update_seq(self._params, i)
            self.assertEqual(
                info["update_seqs"][str(i)], expected_seq,
                "right update seq number (%d) for partition %d" %
                (expected_seq, i + 1))

        # print "Adding 1 new document to each partition"
        new_docs = []
        for i in xrange(self._params["nparts"]):
            server = self._params["server"]
            db = self._params["server"][self._params["setname"] + "/" + str(i)]
            value = total_doc_count + i + 1
            new_doc = {
                "_id": str(value),
                "integer": value,
                "string": str(value)
            }
            new_docs.append(new_doc)
            db.save(new_doc)

        new_total_doc_count = common.set_doc_count(
            self._params, range(self._params["nparts"]))
        self.assertEqual(new_total_doc_count,
                         (total_doc_count + len(new_docs)),
                         "N documents were added")
        total_doc_count = new_total_doc_count

        # print "Querying view again"
        (resp, view_result) = common.query(self._params, "mapview")

        self.assertEqual(len(view_result["rows"]), total_doc_count,
                         "number of received rows is %d" % total_doc_count)
        self.assertEqual(view_result["total_rows"], total_doc_count,
                         "total_rows is %d" % total_doc_count)
        common.test_keys_sorted(view_result)

        # print "Verifying group info"
        info = common.get_set_view_info(self._params)
        self.assertEqual(info["active_partitions"],
                         range(self._params["nparts"]),
                         "right active partitions list")
        self.assertEqual(info["passive_partitions"], [],
                         "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [],
                         "right cleanup partitions list")
        for i in xrange(self._params["nparts"]):
            expected_seq = common.partition_update_seq(self._params, i)
            self.assertEqual(
                info["update_seqs"][str(i)], expected_seq,
                "right update seq number (%d) for partition %d" %
                (expected_seq, i + 1))

        # print "Marking half of the partitions as passive"
        passive = range(self._params["nparts"] / 2, self._params["nparts"])
        active = range(self._params["nparts"] / 2)
        common.set_partition_states(self._params,
                                    passive=range(self._params["nparts"] / 2,
                                                  self._params["nparts"]))

        # print "Verifying group info"
        info = common.get_set_view_info(self._params)
        self.assertEqual(info["active_partitions"], active,
                         "right active partitions list")
        self.assertEqual(info["passive_partitions"], passive,
                         "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [],
                         "right cleanup partitions list")
        for i in xrange(self._params["nparts"]):
            expected_seq = common.partition_update_seq(self._params, i)
            self.assertEqual(
                info["update_seqs"][str(i)], expected_seq,
                "right update seq number (%d) for partition %d" %
                (expected_seq, i + 1))

        # print "Querying view again"
        (resp, view_result) = common.query(self._params, "mapview")

        expected_row_count = common.set_doc_count(self._params, active)
        self.assertEqual(len(view_result["rows"]), expected_row_count,
                         "number of received rows is %d" % expected_row_count)
        common.test_keys_sorted(view_result)

        for row in view_result['rows']:
            if row["key"] >= 2001:
                key_part = ((row["key"] - 2000) % self._params["nparts"]) - 1
            else:
                key_part = (row["key"] % self._params["nparts"]) - 1
            self.assertTrue(
                key_part in active,
                "Key %d from passive partition not in result set" % row["key"])

        # print "Marking half of the partitions for cleanup"
        common.set_partition_states(self._params, cleanup=passive)
        cleanup = passive

        common.compact_set_view(self._params)

        # print "Verifying group info"
        info = common.get_set_view_info(self._params)
        self.assertEqual(info["active_partitions"], active,
                         "right active partitions list")
        self.assertEqual(info["passive_partitions"], [],
                         "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [],
                         "right cleanup partitions list")
        self.assertEqual(info["stats"]["compactions"], 1, "1 compaction")
        self.assertEqual(info["stats"]["cleanups"], 1, "1 full cleanup")
        for i in active:
            expected_seq = common.partition_update_seq(self._params, i)
            self.assertEqual(
                info["update_seqs"][str(i)], expected_seq,
                "right update seq number (%d) for partition %d" %
                (expected_seq, i + 1))
Esempio n. 8
0
    def test_update_cleanup(self):
        # print "Triggering initial view update"
        t0 = time.time()
        (resp, view_result) = common.query(self._params, "mapview", {"limit": "1"})
        # print "Update took %.2f seconds" % (time.time() - t0)

        # print "Verifying group info"

        info = common.get_set_view_info(self._params)
        stats = info["stats"]

        self.assertEqual(info["active_partitions"], [0, 1, 2, 3], "right active partitions list")
        self.assertEqual(info["passive_partitions"], [], "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [], "right cleanup partitions list")
        self.assertEqual(stats["full_updates"], 1, "1 full update done so far")
        self.assertEqual(stats["stopped_updates"], 0, "no updater interruptions so far")
        self.assertEqual(stats["cleanups"], 0, "0 cleanups done")
        self.assertEqual(stats["cleanup_interruptions"], 0, "no cleanup interruptions so far")

        # print "Adding new partitions 5, 6, 7 and 8 and marking partitions 1 and 4 for cleanup"
        common.set_partition_states(self._params, active=[4, 5, 6, 7], cleanup=[0, 3])

        # print "Querying view (should trigger update + cleanup)"
        t0 = time.time()
        (resp, view_result) = common.query(self._params, "mapview")
        t1 = time.time()

        # print "Verifying query results"

        expected_total = common.set_doc_count(self._params, [1, 2, 4, 5, 6, 7])
        self.assertEqual(view_result["total_rows"], expected_total, "total rows is %d" % expected_total)
        self.assertEqual(len(view_result["rows"]), expected_total, "got %d tows" % expected_total)
        common.test_keys_sorted(view_result)

        all_keys = {}
        for r in view_result["rows"]:
            all_keys[r["key"]] = True

        for key in xrange(1, self._params["ndocs"], self._params["nparts"]):
            self.assertFalse(key in all_keys, "Key %d (partition 1) not in query result after update+cleanup" % key)
        for key in xrange(2, self._params["ndocs"], self._params["nparts"]):
            self.assertTrue(key in all_keys, "Key %d (partition 2) in query result after update+cleanup" % key)
        for key in xrange(3, self._params["ndocs"], self._params["nparts"]):
            self.assertTrue(key in all_keys, "Key %d (partition 3) in query result after update+cleanup" % key)
        for key in xrange(4, self._params["ndocs"], self._params["nparts"]):
            self.assertFalse(key in all_keys, "Key %d (partition 4) not in query result after update+cleanup" % key)
        for key in xrange(5, self._params["ndocs"], self._params["nparts"]):
            self.assertTrue(key in all_keys, "Key %d (partition 5) in query result after update+cleanup" % key)
        for key in xrange(6, self._params["ndocs"], self._params["nparts"]):
            self.assertTrue(key in all_keys, "Key %d (partition 6) in query result after update+cleanup" % key)
        for key in xrange(7, self._params["ndocs"], self._params["nparts"]):
            self.assertTrue(key in all_keys, "Key %d (partition 7) in query result after update+cleanup" % key)
        for key in xrange(8, self._params["ndocs"], self._params["nparts"]):
            self.assertTrue(key in all_keys, "Key %d (partition 8) in query result after update+cleanup" % key)

        # print "Verifying group info"

        info = common.get_set_view_info(self._params)
        stats = info["stats"]

        self.assertEqual(info["active_partitions"], [1, 2, 4, 5, 6, 7], "right active partitions list")
        self.assertEqual(info["passive_partitions"], [], "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [], "right cleanup partitions list")
        self.assertEqual(stats["full_updates"], 2, "2 full updates done so far")
        self.assertEqual(stats["stopped_updates"], 0, "no updater interruptions so far")
        self.assertEqual(stats["cleanups"], 1, "1 full cleanup done")
        self.assertEqual(stats["cleanup_interruptions"], 1, "1 cleanup interruption done")

        for i in info["active_partitions"]:
            expected_seq = common.partition_update_seq(self._params, i)
            self.assertTrue(str(i) in info["update_seqs"], "partition %d in info.update_seqs" % (i + 1))
            self.assertEqual(info["update_seqs"][str(i)], expected_seq, "right seq in info.update_seqs[%d]" % i)
Esempio n. 9
0
    def do_test_set_passive_during_compaction(self):
        # print "Querying map view"
        (map_resp, map_view_result) = common.query(self._params, "mapview1")

        doc_count = common.set_doc_count(self._params, [0, 1, 2, 3])
        self.assertEqual(map_view_result["total_rows"], doc_count,
                         "Query returned %d total_rows" % doc_count)
        self.assertEqual(len(map_view_result["rows"]), doc_count,
                         "Query returned %d rows" % doc_count)

        common.test_keys_sorted(map_view_result)

        # print "Verifying set view group info"
        info = common.get_set_view_info(self._params)
        self.assertEqual(info["active_partitions"], [0, 1, 2, 3], "right active partitions list")
        self.assertEqual(info["passive_partitions"], [], "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [], "right cleanup partitions list")
        for i in [0, 1, 2, 3]:
            db = self._params["server"][self._params["setname"] + "/" + str(i)]
            seq = db.info()["update_seq"]
            self.assertEqual(info["update_seqs"][str(i)], seq,
                             "right update seq for partition %d" % (i + 1))

        # print "Triggering view compaction"
        common.compact_set_view(self._params, False)

        # print "Marking partition 4 as passive"
        common.set_partition_states(self._params, passive = [3])

        info = common.get_set_view_info(self._params)
        self.assertEqual(info["active_partitions"], [0, 1, 2], "right active partitions list")
        self.assertEqual(info["passive_partitions"], [3], "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [], "right cleanup partitions list")

        # print "Waiting for compaction to finish"
        count = 0
        while info["stats"]["compactions"] < 1:
            time.sleep(0.5)
            count += 1
            info = common.get_set_view_info(self._params)

        self.assertTrue((count > 0), "Compaction was running when the partition states were updated")

        # print "Verifying group info"
        info = common.get_set_view_info(self._params)
        self.assertEqual(info["active_partitions"], [0, 1, 2], "right active partitions list")
        self.assertEqual(info["passive_partitions"], [3], "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [], "right cleanup partitions list")

        # print "Querying map view again"
        (map_resp, map_view_result) = common.query(self._params, "mapview1")

        expected = common.set_doc_count(self._params, [0, 1, 2])
        self.assertEqual(map_view_result["total_rows"], doc_count,
                         "Query returned %d total_rows" % doc_count)
        self.assertEqual(len(map_view_result["rows"]), expected,
                         "Query returned %d rows" % expected)

        common.test_keys_sorted(map_view_result)

        all_keys = {}
        for r in map_view_result["rows"]:
            all_keys[r["key"]] = True

        for key in xrange(4, self._params["ndocs"], self._params["nparts"]):
            self.assertFalse(key in all_keys,
                             "Key %d not in result after partition 4 set to passive" % key)

        # print "Triggering view compaction"
        common.compact_set_view(self._params, False)

        # print "Adding two new partitions, 5 and 6, as passive while compaction is running"
        common.set_partition_states(self._params, passive = [4, 5])

        # print "Waiting for compaction to finish"
        info = common.get_set_view_info(self._params)
        count = 0
        while info["stats"]["compactions"] < 2:
            time.sleep(0.5)
            count += 1
            info = common.get_set_view_info(self._params)

        self.assertTrue((count > 0), "Compaction was running when the partition states were updated")

        # print "Verifying group info"
        info = common.get_set_view_info(self._params)
        self.assertEqual(info["active_partitions"], [0, 1, 2], "right active partitions list")
        self.assertEqual(info["passive_partitions"], [3, 4, 5], "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [], "right cleanup partitions list")
        for i in [0, 1, 2, 3, 4, 5]:
            self.assertTrue(str(i) in info["update_seqs"], "%d in info.update_seqs" % i)
        for i in [6, 7]:
            self.assertFalse(str(i) in info["update_seqs"], "%d not in info.update_seqs" % i)

        # print "Querying map view again"
        (map_resp, map_view_result2) = common.query(self._params, "mapview1")
        self.assertEqual(map_view_result2["rows"],  map_view_result["rows"], "Same result set as before")

        total_doc_count = common.set_doc_count(self._params, [0, 1, 2, 3, 4, 5, 6, 7])
        # print "Adding 1 new document to each partition"
        new_docs = []
        for i in [0, 1, 2, 3, 4, 5, 6, 7]:
            server = self._params["server"]
            db = self._params["server"][self._params["setname"] + "/" + str(i)]
            value = total_doc_count + i + 1
            new_doc = {
                "_id": str(value),
                "integer": value,
                "string": str(value)
                }
            new_docs.append(new_doc)
            db.save(new_doc)

        new_total_doc_count = common.set_doc_count(self._params, [0, 1, 2, 3, 4, 5, 6, 7])
        self.assertEqual(new_total_doc_count, (total_doc_count + 8), "8 documents added")
        self.assertEqual(len(new_docs), 8, "8 documents added")

        info = common.get_set_view_info(self._params)
        if info["updater_running"]:
            # print "Waiting for updater to finish"
            self.assertEqual(info["updater_state"], "updating_passive",
                             "updater state is updating_passive")
            while True:
                info = common.get_set_view_info(self._params)
                if info["updater_running"]:
                    self.assertEqual(info["updater_state"], "updating_passive",
                                     "updater state is updating_passive")
                    time.sleep(3)
                else:
                    break

        expected_row_count = common.set_doc_count(self._params, [0, 1, 2])
        expected_total_rows = common.set_doc_count(self._params, [0, 1, 2, 3, 4, 5])

        # print "Querying map view again"
        (map_resp, map_view_result) = common.query(self._params, "mapview1")

        self.assertEqual(len(map_view_result["rows"]), expected_row_count, "len(rows) is %d" % expected_row_count)
        common.test_keys_sorted(map_view_result)

        # print "Verifying group info"
        info = common.get_set_view_info(self._params)
        self.assertEqual(info["active_partitions"], [0, 1, 2], "right active partitions list")
        self.assertEqual(info["passive_partitions"], [3, 4, 5], "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [], "right cleanup partitions list")
        for i in [0, 1, 2, 3, 4, 5]:
            self.assertTrue(str(i) in info["update_seqs"], "%d in info.update_seqs" % i)
            expected_seq = common.partition_update_seq(self._params, i)
            self.assertEqual(info["update_seqs"][str(i)], expected_seq,
                             "info.update_seqs[%d] is %d" % (i, expected_seq))
Esempio n. 10
0
    def do_test_set_passive_partitions_when_updater_is_running(self):
        # print "Re-creating databases"
        common.create_dbs(self._params)
        common.populate(self._params)
        # print "Configuring set view with all partitions active"
        common.define_set_view(self._params, [0, 1, 2, 3], [])

        # print "Querying map view in steady state with ?stale=update_after"
        (resp, view_result) = common.query(self._params, "mapview", {"stale": "update_after"})

        self.assertEqual(len(view_result["rows"]), 0, "Received empty row set")
        self.assertEqual(view_result["total_rows"], 0, "Received empty row set")

        # print "Marking partition 4 as passive"
        common.set_partition_states(self._params, passive = [3])

        info = common.get_set_view_info(self._params)
        self.assertEqual(info["active_partitions"], [0, 1, 2], "right active partitions list")
        self.assertEqual(info["passive_partitions"], [3], "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [], "right cleanup partitions list")

        # print "Waiting for the set view updater to finish"
        iterations = 0
        while True:
            info = common.get_set_view_info(self._params)
            if info["updater_running"]:
                iterations += 1
            else:
                break

        self.assertTrue(iterations > 0, "Updater was running when partition 4 was set to passive")
        # print "Verifying set view group info"
        info = common.get_set_view_info(self._params)
        self.assertEqual(info["active_partitions"], [0, 1, 2], "right active partitions list")
        self.assertEqual(info["passive_partitions"], [3], "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [],  "right cleanup partitions list")

        # print "Querying map view again"
        (resp, view_result) = common.query(self._params, "mapview")

        doc_count = common.set_doc_count(self._params)
        expected_row_count = common.set_doc_count(self._params, [0, 1, 2])
        self.assertEqual(view_result["total_rows"], doc_count, "Query returned %d total_rows" % doc_count)
        self.assertEqual(len(view_result["rows"]), expected_row_count, "Query returned %d rows" % expected_row_count)

        common.test_keys_sorted(view_result)

        all_keys = {}
        for r in view_result["rows"]:
            all_keys[r["key"]] = True

        for key in xrange(4, doc_count, self._params["nparts"]):
            self.assertFalse(key in all_keys,
                             "Key %d not in result after partition 4 was set to passive" % key)

        # print "Adding 2 new documents to partition 4"
        server = self._params["server"]
        db4 = server[self._params["setname"] + "/3"]
        new_doc1 = {"_id": "999999999", "integer": 999999999, "string": "999999999"}
        new_doc2 = {"_id": "000", "integer": -1111, "string": "000"}
        db4.save(new_doc1)
        db4.save(new_doc2)

        # print "Querying map view again"
        (resp, view_result2) = common.query(self._params, "mapview")
        self.assertEqual(view_result2["rows"], view_result["rows"], "Same result set as before")

        # print "Verifying set view group info"
        info = common.get_set_view_info(self._params)
        self.assertEqual(info["active_partitions"], [0, 1, 2], "right active partitions list")
        self.assertEqual(info["passive_partitions"], [3], "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [],  "right cleanup partitions list")

        total_doc_count = common.set_doc_count(self._params)
        # print "Changing partition 4 from passive to active"
        common.set_partition_states(self._params, active = [3])

        # print "Querying map view again"
        (resp, view_result) = common.query(self._params, "mapview")

        self.assertEqual(view_result["total_rows"], total_doc_count, "total_rows is %d" % total_doc_count)
        self.assertEqual(len(view_result["rows"]), total_doc_count, "number of rows returned is %d" % total_doc_count)
        common.test_keys_sorted(view_result)

        self.assertEqual(view_result["rows"][0]["key"], new_doc2["integer"], "new_doc2 reflected in result set at first row")
        self.assertEqual(view_result["rows"][-1]["key"], new_doc1["integer"], "new_doc1 reflected in result set at last row")

        # print "Verifying set view group info"
        info = common.get_set_view_info(self._params)
        self.assertEqual(info["active_partitions"], [0, 1, 2, 3], "right active partitions list")
        self.assertEqual(info["passive_partitions"], [], "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [],  "right cleanup partitions list")
        for i in [0, 1, 2, 3]:
            expected_seq = common.partition_update_seq(self._params, i)
            self.assertEqual(info["update_seqs"][str(i)], expected_seq,
                             "right update seq number (%d) for partition %d" % (expected_seq, i + 1))
Esempio n. 11
0
    def test_many_partitions(self):
        total_doc_count = common.set_doc_count(self._params, range(self._params["nparts"]))

        # print "Querying view"
        (resp, view_result) = common.query(self._params, "mapview")

        self.assertEqual(len(view_result["rows"]), total_doc_count, "number of received rows is %d" % total_doc_count)
        self.assertEqual(view_result["total_rows"], total_doc_count, "total_rows is %d" % total_doc_count)
        common.test_keys_sorted(view_result)

        # print "Verifying group info"
        info = common.get_set_view_info(self._params)
        self.assertEqual(info["active_partitions"], range(self._params["nparts"]), "right active partitions list")
        self.assertEqual(info["passive_partitions"], [], "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [], "right cleanup partitions list")
        for i in xrange(self._params["nparts"]):
            expected_seq = common.partition_update_seq(self._params, i)
            self.assertEqual(info["update_seqs"][str(i)], expected_seq,
                             "right update seq number (%d) for partition %d" % (expected_seq, i + 1))

        # print "Adding 1 new document to each partition"
        new_docs = []
        for i in xrange(self._params["nparts"]):
            server = self._params["server"]
            db = self._params["server"][self._params["setname"] + "/" + str(i)]
            value = total_doc_count + i + 1
            new_doc = {
                "_id": str(value),
                "integer": value,
                "string": str(value)
                }
            new_docs.append(new_doc)
            db.save(new_doc)

        new_total_doc_count = common.set_doc_count(self._params, range(self._params["nparts"]))
        self.assertEqual(new_total_doc_count, (total_doc_count + len(new_docs)), "N documents were added")
        total_doc_count = new_total_doc_count

        # print "Querying view again"
        (resp, view_result) = common.query(self._params, "mapview")

        self.assertEqual(len(view_result["rows"]), total_doc_count, "number of received rows is %d" % total_doc_count)
        self.assertEqual(view_result["total_rows"], total_doc_count, "total_rows is %d" % total_doc_count)
        common.test_keys_sorted(view_result)

        # print "Verifying group info"
        info = common.get_set_view_info(self._params)
        self.assertEqual(info["active_partitions"], range(self._params["nparts"]), "right active partitions list")
        self.assertEqual(info["passive_partitions"], [], "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [], "right cleanup partitions list")
        for i in xrange(self._params["nparts"]):
            expected_seq = common.partition_update_seq(self._params, i)
            self.assertEqual(info["update_seqs"][str(i)], expected_seq,
                             "right update seq number (%d) for partition %d" % (expected_seq, i + 1))

        # print "Marking half of the partitions as passive"
        passive = range(self._params["nparts"] / 2, self._params["nparts"])
        active = range(self._params["nparts"] / 2)
        common.set_partition_states(
            self._params,
            passive = range(self._params["nparts"] / 2, self._params["nparts"])
            )

        # print "Verifying group info"
        info = common.get_set_view_info(self._params)
        self.assertEqual(info["active_partitions"], active, "right active partitions list")
        self.assertEqual(info["passive_partitions"], passive, "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [], "right cleanup partitions list")
        for i in xrange(self._params["nparts"]):
            expected_seq = common.partition_update_seq(self._params, i)
            self.assertEqual(info["update_seqs"][str(i)], expected_seq,
                             "right update seq number (%d) for partition %d" % (expected_seq, i + 1))

        # print "Querying view again"
        (resp, view_result) = common.query(self._params, "mapview")

        expected_row_count = common.set_doc_count(self._params, active)
        self.assertEqual(len(view_result["rows"]), expected_row_count, "number of received rows is %d" % expected_row_count)
        common.test_keys_sorted(view_result)

        for row in view_result['rows']:
            if row["key"] >= 2001:
                key_part = ((row["key"] - 2000) % self._params["nparts"]) - 1
            else:
                key_part = (row["key"] % self._params["nparts"]) - 1
            self.assertTrue(key_part in active, "Key %d from passive partition not in result set" % row["key"])

        # print "Marking half of the partitions for cleanup"
        common.set_partition_states(
            self._params,
            cleanup = passive
            )
        cleanup = passive

        common.compact_set_view(self._params)

        # print "Verifying group info"
        info = common.get_set_view_info(self._params)
        self.assertEqual(info["active_partitions"], active, "right active partitions list")
        self.assertEqual(info["passive_partitions"], [], "right passive partitions list")
        self.assertEqual(info["cleanup_partitions"], [], "right cleanup partitions list")
        self.assertEqual(info["stats"]["compactions"], 1, "1 compaction")
        self.assertEqual(info["stats"]["cleanups"], 1, "1 full cleanup")
        for i in active:
            expected_seq = common.partition_update_seq(self._params, i)
            self.assertEqual(info["update_seqs"][str(i)], expected_seq,
                             "right update seq number (%d) for partition %d" % (expected_seq, i + 1))