hawq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nh...@apache.org
Subject incubator-hawq git commit: HAWQ-156. Fix hd_work_mgr unit tests.
Date Fri, 13 Nov 2015 19:01:40 GMT
Repository: incubator-hawq
Updated Branches:
  refs/heads/master 2ee1ed909 -> f0f623872


HAWQ-156. Fix hd_work_mgr unit tests.

The tests were using an the wrong cast to access segment info. The old struct CdbComponentDatabaseInfo
should have been replaced by Segment.


Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/f0f62387
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/f0f62387
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/f0f62387

Branch: refs/heads/master
Commit: f0f623872bf4436d553ec07703325dcdb73ffc52
Parents: 2ee1ed9
Author: Noa Horn <nhorn@pivotal.io>
Authored: Thu Nov 12 17:18:33 2015 -0800
Committer: Noa Horn <nhorn@pivotal.io>
Committed: Fri Nov 13 10:31:03 2015 -0800

----------------------------------------------------------------------
 ...ork_mgr_distribute_work_2_gp_segments_test.c | 46 +++++---------
 ...ork_mgr_do_segment_clustering_by_host_test.c | 24 ++------
 .../access/external/test/hd_work_mgr_mock.c     | 46 ++------------
 .../access/external/test/hd_work_mgr_mock.h     | 63 ++------------------
 4 files changed, 27 insertions(+), 152 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f0f62387/src/backend/access/external/test/hd_work_mgr_distribute_work_2_gp_segments_test.c
----------------------------------------------------------------------
diff --git a/src/backend/access/external/test/hd_work_mgr_distribute_work_2_gp_segments_test.c
b/src/backend/access/external/test/hd_work_mgr_distribute_work_2_gp_segments_test.c
index aca45b0..b829db5 100644
--- a/src/backend/access/external/test/hd_work_mgr_distribute_work_2_gp_segments_test.c
+++ b/src/backend/access/external/test/hd_work_mgr_distribute_work_2_gp_segments_test.c
@@ -43,11 +43,10 @@ static void print_allocated_fragments(List **allocated_fragments, int
total_segs
 static char* print_one_allocated_data_fragment(AllocatedDataFragment *frag, int seg_index);
 static char* find_segment_ip_by_index(int seg_index);
 static char** create_cluster(int num_hosts);
-static char** clean_cluster(char** cluster, int num_hosts);
+static void clean_cluster(char** cluster, int num_hosts);
 static char** create_array_of_segs(char **cluster, int num_hosts, int num_segments_on_host);
 static void clean_array_of_segs(char **array_of_segs, int number_of_segments);
-static bool* create_array_of_primaries(int number_of_segments);
-static char** print_cluster(char** cluster, int num_hosts);
+static void print_cluster(char** cluster, int num_hosts);
 static void print_segments_list();
 void clean_allocated_fragments(List **allocated_fragments, int total_segs);
 static void validate_total_fragments_allocated(List **allocated_fragments, int total_segs,
int input_total_fragments);
@@ -216,7 +215,6 @@ static void test__distribute_work_to_gp_segments(TestInputData *input)
 	List **segs_allocated_data = NULL;
 	List * input_fragments_list = NIL;
 	char** array_of_segs = NULL;
-	bool *array_of_primaries;
 	int total_segs;
 	bool cluster_size_not_exceeded = input->m_num_hosts_in_cluster <=  65025;
 	
@@ -258,14 +256,12 @@ static void test__distribute_work_to_gp_segments(TestInputData *input)
 	/* 4. Input - hawq segments */
 	total_segs = num_hosts_in_cluster * num_segments_on_host;
 	array_of_segs = create_array_of_segs(cluster, num_hosts_in_cluster, num_segments_on_host);

-	array_of_primaries = create_array_of_primaries(total_segs);
 		
-	buildCdbComponentDatabases(total_segs, array_of_segs, array_of_primaries);	
-	if (enable_print_input_segments)
-		print_segments_list();
+    /* 5. Build QueryResource (acting hawq segments) */
+    buildQueryResource(total_segs, array_of_segs);
+    if (enable_print_input_segments)
+    	print_segments_list();
 
-    /* 5. Build QueryResource */
-    buildQueryResource(num_hosts_in_cluster*num_segments_on_host, array_of_segs);
     will_return(GetActiveQueryResource, resource);
     will_return(GetActiveQueryResource, resource);
 
@@ -281,11 +277,9 @@ static void test__distribute_work_to_gp_segments(TestInputData *input)
 	
 	/* 8. Cleanup */
 	freeQueryResource();
-	restoreCdbComponentDatabases();
 	clean_cluster(cluster, num_hosts_in_cluster);
 	clean_array_of_segs(array_of_segs, total_segs);
 	clean_allocated_fragments(segs_allocated_data, total_segs);
-	pfree(array_of_primaries);
 }
 
 /* create an array of segments based on the host in the cluster and the number of Hawq segments
on host */
@@ -316,16 +310,6 @@ static void clean_array_of_segs(char **array_of_segs, int total_segments)
 	pfree(array_of_segs);
 }
 
-static bool* create_array_of_primaries(int total_segments)
-{
-	int i;
-	bool *primaries = (bool*)palloc0(total_segments * sizeof(bool));
-	for (i = 0; i < total_segments; i++)
-		primaries[i] = true;
-		
-	return primaries;
-}
-
 /* gives an ip to each host in a num_hosts size cluster */
 static char** create_cluster(int num_hosts)
 {
@@ -355,7 +339,7 @@ static char** create_cluster(int num_hosts)
 }
 
 /* release memory */
-static char** clean_cluster(char** cluster, int num_hosts)
+static void clean_cluster(char** cluster, int num_hosts)
 {
 	int i;
 	
@@ -368,7 +352,7 @@ static char** clean_cluster(char** cluster, int num_hosts)
 }
 
 /* show the cluster*/
-static char** print_cluster(char** cluster, int num_hosts)
+static void print_cluster(char** cluster, int num_hosts)
 {
 	int i;
 	StringInfoData msg;
@@ -391,13 +375,12 @@ static char** print_cluster(char** cluster, int num_hosts)
 static void print_segments_list()
 {
 	StringInfoData msg;
-	CdbComponentDatabases *test_cdb = GpAliveSegmentsInfo.cdbComponentDatabases;
 	initStringInfo(&msg);
 
-	for (int i = 0; i < test_cdb->total_segment_dbs; ++i)
+	for (int i = 0; i < resource->numSegments; ++i)
 	{
-		CdbComponentDatabaseInfo* component = &test_cdb->segment_db_info[i];
-		appendStringInfo(&msg, "\nsegment -- index: %d, ip: %s", component->segindex, component->hostip);
+		Segment* seg = list_nth(resource->segments, i);
+		appendStringInfo(&msg, "\nsegment -- index: %d, ip: %s", seg->segindex, seg->hostip);
 	}
 	
 	elog(FRAGDEBUG, "%s", msg.data);
@@ -407,13 +390,12 @@ static void print_segments_list()
 /* returns the ip  of the segment's host */
 static char* find_segment_ip_by_index(int seg_index)
 {	
-	CdbComponentDatabases *test_cdb = GpAliveSegmentsInfo.cdbComponentDatabases;
-	if (seg_index < 0 || seg_index >= test_cdb->total_segment_dbs)
+	if (seg_index < 0 || seg_index >= resource->numSegments)
 		assert_true(false);
 		
-	for (int i = 0; i < test_cdb->total_segment_dbs; ++i)
+	for (int i = 0; i < resource->numSegments; ++i)
 	{
-		CdbComponentDatabaseInfo* seg = &test_cdb->segment_db_info[i];
+		Segment* seg = list_nth(resource->segments, i);
 		if (seg->segindex == seg_index)
 			return seg->hostip;
 	}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f0f62387/src/backend/access/external/test/hd_work_mgr_do_segment_clustering_by_host_test.c
----------------------------------------------------------------------
diff --git a/src/backend/access/external/test/hd_work_mgr_do_segment_clustering_by_host_test.c
b/src/backend/access/external/test/hd_work_mgr_do_segment_clustering_by_host_test.c
index f668ccf..ce8e61d 100644
--- a/src/backend/access/external/test/hd_work_mgr_do_segment_clustering_by_host_test.c
+++ b/src/backend/access/external/test/hd_work_mgr_do_segment_clustering_by_host_test.c
@@ -34,8 +34,8 @@ void check_segment_info(List* segment_list, int list_index,
 						const char* expected_hostip)
 {
 
-	CdbComponentDatabaseInfo* seg_info =
-			(CdbComponentDatabaseInfo*)lfirst(list_nth_cell(segment_list, list_index));
+	Segment* seg_info =
+			(Segment*)(list_nth(segment_list, list_index));
 	assert_string_equal(seg_info->hostip, expected_hostip);
 }
 
@@ -50,34 +50,21 @@ test__do_segment_clustering_by_host__10SegmentsOn3Hosts(void **state)
 	ListCell* cell = NULL;
 	GpHost* gphost = NULL;
 	List* segs = NIL;
-	CdbComponentDatabaseInfo* seg_info = NULL;
 
 	char* array_of_segs[10] =
 		{"1.2.3.1", "1.2.3.1", "1.2.3.1", "1.2.3.1",
 		 "1.2.3.2", "1.2.3.2", "1.2.3.2",
 		 "1.2.3.3", "1.2.3.3", "1.2.3.3"
 	};
-	bool array_of_primaries[10] =
-	{
-		true, true, true, true,
-		true, true, true,
-		true, true, true
-	};
 	int number_of_segments = 10;
 	/* sanity */
 	assert_true(number_of_segments == (sizeof(array_of_segs) / sizeof(array_of_segs[0])));
-	assert_true(number_of_segments == (sizeof(array_of_primaries) / sizeof(array_of_primaries[0])));
-
-	buildCdbComponentDatabases(number_of_segments, array_of_segs, array_of_primaries);
-
-	CdbComponentDatabases *cdb = GpAliveSegmentsInfo.cdbComponentDatabases;
-
-	/* sanity for cdbComponentDatabases building*/
-	assert_int_equal(cdb->total_segment_dbs, number_of_segments);
-	assert_string_equal(cdb->segment_db_info[4].hostip, array_of_segs[4]);
 
 	/* build QueryResource */
 	buildQueryResource(10, array_of_segs);
+	/* sanity for QueryResource building*/
+	assert_int_equal(resource->numSegments, 10);
+	assert_string_equal(((Segment*)list_nth(resource->segments, 4))->hostip, array_of_segs[4]);
 	will_return(GetActiveQueryResource, resource);
 
 	/* test do_segment_clustering_by_host */
@@ -113,6 +100,5 @@ test__do_segment_clustering_by_host__10SegmentsOn3Hosts(void **state)
 	}
 
 	freeQueryResource();
-	restoreCdbComponentDatabases();
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f0f62387/src/backend/access/external/test/hd_work_mgr_mock.c
----------------------------------------------------------------------
diff --git a/src/backend/access/external/test/hd_work_mgr_mock.c b/src/backend/access/external/test/hd_work_mgr_mock.c
index c4ed128..723c053 100644
--- a/src/backend/access/external/test/hd_work_mgr_mock.c
+++ b/src/backend/access/external/test/hd_work_mgr_mock.c
@@ -26,57 +26,21 @@
 #include "hd_work_mgr_mock.h"
 
 /*
- * Helper functions to create and restore GpAliveSegmentsInfo.cdbComponentDatabases element
+ * Helper functions to create and free QueryResource element
  * used by hd_work_mgr
  */
 
-/*
- * Builds an array of CdbComponentDatabaseInfo.
+/* Builds the QueryResource for a query.
  * Each segment is assigned a sequence number and an ip.
  * segs_num - the number of segments
  * segs_hostips - array of the ip of each segment
- * primaries_map - array of which segments are primaries
  */
-void buildCdbComponentDatabases(int segs_num,
-								char* segs_hostips[],
-								bool primaries_map[])
-{
-	CdbComponentDatabases *test_cdb = palloc0(sizeof(CdbComponentDatabases));
-	CdbComponentDatabaseInfo* component = NULL;
-	test_cdb->total_segment_dbs = segs_num;
-	test_cdb->segment_db_info =
-			(CdbComponentDatabaseInfo *) palloc0(sizeof(CdbComponentDatabaseInfo) * test_cdb->total_segment_dbs);
-
-	for (int i = 0; i < test_cdb->total_segment_dbs; ++i)
-	{
-		component = &test_cdb->segment_db_info[i];
-		component->segindex = i;
-		component->role = primaries_map[i] ? SEGMENT_ROLE_PRIMARY : SEGMENT_ROLE_MIRROR;
-		component->hostip = pstrdup(segs_hostips[i]);
-	}
-
-	orig_cdb = GpAliveSegmentsInfo.cdbComponentDatabases;
-	orig_seg_count = GpAliveSegmentsInfo.aliveSegmentsCount;
-	GpAliveSegmentsInfo.cdbComponentDatabases = test_cdb;
-	GpAliveSegmentsInfo.aliveSegmentsCount = segs_num;
-}
-
-void restoreCdbComponentDatabases()
-{
-	/* free test CdbComponentDatabases */
-	if (GpAliveSegmentsInfo.cdbComponentDatabases)
-		freeCdbComponentDatabases(GpAliveSegmentsInfo.cdbComponentDatabases);
-
-	GpAliveSegmentsInfo.cdbComponentDatabases = orig_cdb;
-	GpAliveSegmentsInfo.aliveSegmentsCount = orig_seg_count;
-}
-
-/* Builds the QueryResource for a query */
 void buildQueryResource(int segs_num,
                         char * segs_hostips[])
 {
-	resource = (QueryResource *)palloc(sizeof(QueryResource));
+	resource = (QueryResource *)palloc0(sizeof(QueryResource));
 
+	resource->numSegments = segs_num;
 	resource->segments = NULL;
 	for (int i = 0; i < segs_num; ++i)
 	{
@@ -87,8 +51,6 @@ void buildQueryResource(int segs_num,
 
 		resource->segments = lappend(resource->segments, segment);
 	}
-
-	return resource;
 }
 
 /* Restores the QueryResource for a query */

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f0f62387/src/backend/access/external/test/hd_work_mgr_mock.h
----------------------------------------------------------------------
diff --git a/src/backend/access/external/test/hd_work_mgr_mock.h b/src/backend/access/external/test/hd_work_mgr_mock.h
index c37db78..cb561bb 100644
--- a/src/backend/access/external/test/hd_work_mgr_mock.h
+++ b/src/backend/access/external/test/hd_work_mgr_mock.h
@@ -28,74 +28,19 @@
 #include "c.h"
 #include "../hd_work_mgr.c"
 
-static CdbComponentDatabases *orig_cdb = NULL;
-static int orig_seg_count = -1;
 
 static QueryResource * resource = NULL;
 
-struct AliveSegmentsInfo
-{
-	uint64			fts_statusVersion;
-	TransactionId	tid;
-
-	/* Release gangs */
-	bool			cleanGangs;
-
-	/* Used for debug & test */
-	bool			forceUpdate;
-	int				failed_segmentid_start;
-	int				failed_segmentid_number;
-
-	/* Used for disptacher. */
-	int4			aliveSegmentsCount;
-	int4			singleton_segindex;
-	Bitmapset		*aliveSegmentsBitmap;
-	struct CdbComponentDatabases *cdbComponentDatabases;
-};
-
-typedef struct AliveSegmentsInfo AliveSegmentsInfo;
-
-AliveSegmentsInfo GpAliveSegmentsInfo = {0, 0, false, false, 0, 0, UNINITIALIZED_GP_IDENTITY_VALUE,
0, NULL, NULL};
-
-/*
- * Helper functions copied from backend/cdb/cdbutils.c
- */
-
 /*
- * _freeCdbComponentDatabases
- *
- * Releases the storage occupied by the CdbComponentDatabases
- * struct pointed to by the argument.
- */
-void
-_freeCdbComponentDatabases(CdbComponentDatabases *pDBs);
-
-/*
- * _freeCdbComponentDatabaseInfo:
- * Releases any storage allocated for members variables of a CdbComponentDatabaseInfo struct.
- */
-void
-_freeCdbComponentDatabaseInfo(CdbComponentDatabaseInfo *cdi);
-
-/*
- * Helper functions to create and restore GpAliveSegmentsInfo.cdbComponentDatabases element
+ * Helper functions to create and free QueryResource element
  * used by hd_work_mgr
  */
 
 /*
- * Builds an array of CdbComponentDatabaseInfo.
- * Each segment is assigned a sequence number and an ip.
- * segs_num - the number of segments
- * segs_hostips - array of the ip of each segment
- * primaries_map - array of which segments are primaries
+ * Builds a mock QueryResource which is used when
+ * GetActiveQueryResource is called to get the
+ * list of available segments.
  */
-void buildCdbComponentDatabases(int segs_num,
-								char* segs_hostips[],
-								bool primaries_map[]);
-
-
-void restoreCdbComponentDatabases();
-
 void buildQueryResource(int segs_num,
                         char * segs_hostips[]);
 void freeQueryResource();


Mime
View raw message