Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature-issue#12
Browse files Browse the repository at this point in the history
  • Loading branch information
onderkalaci committed Jan 2, 2015
2 parents 1b2f37c + 46bcf2c commit a3dc6d0
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 11 deletions.
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@
# Object files
*.o
*.ko
*.obj
*.elf

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
Expand All @@ -20,6 +28,19 @@
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# ========
# = Gcov =
# ========

# gcc coverage testing tool files

*.gcno
*.gcda
*.gcov

# ====================
# = Project-Specific =
Expand Down
20 changes: 20 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
language: c
cache: apt
env:
global:
- enable_coverage=yes
matrix:
- PGVERSION=9.4
before_install:
- sudo apt-get update -qq
- sudo update-alternatives --remove-all postmaster.1.gz
- git clone --depth 1 https://gist.github.com/9963879.git tools
- tools/nuke_pg.sh
install:
- sudo pip install cpp-coveralls
- tools/install_pg.sh
before_script: tools/config_and_start_cluster.sh
script: tools/pg_travis_test.sh
after_success:
- sudo chmod 666 *.gcda
- coveralls --exclude test --exclude ruleutils_93.c --exclude ruleutils_94.c
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ REGRESS_OPTS = --launcher=./launcher.sh

EXTRA_CLEAN += ${REGRESS_PREP}

ifeq ($(enable_coverage),yes)
PG_CPPFLAGS += --coverage
SHLIB_LINK += --coverage
EXTRA_CLEAN += *.gcno *.gcda test/*.gcno test/*.gcda
endif

# Let the test's makefile tell us what objects to build.
include test/Makefile

Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# pg_shard

[![Build Status](https://img.shields.io/travis/citusdata/pg_shard.svg)][status]
[![Coverage](https://img.shields.io/coveralls/citusdata/pg_shard.svg)][coverage]
[![Release](https://img.shields.io/github/release/citusdata/pg_shard.svg)][release]
[![License](https://img.shields.io/:license-LGPLv3-blue.svg)][license]

`pg_shard` is a sharding extension for PostgreSQL. It shards and replicates your PostgreSQL tables for horizontal scale and high availability. The extension also seamlessly distributes your SQL statements, without requiring any changes to your application.

As a standalone extension, `pg_shard` addresses many NoSQL use cases. It also enables real-time analytics, and has an easy upgrade path to [CitusDB](http://citusdata.com/) for complex analytical workloads (distributed joins). Further, the extension provides access to standard SQL tools, and powerful PostgreSQL features, such as diverse set of indexes and semi-structured data types.
Expand Down Expand Up @@ -154,4 +159,9 @@ the terms of the GNU Lesser General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option) any
later version.

See the [`LICENSE`](LICENSE) file for full details.
See the [`LICENSE`][license] file for full details.

[status]: https://travis-ci.org/citusdata/pg_shard
[coverage]: https://coveralls.io/r/citusdata/pg_shard
[release]: https://github.com/citusdata/pg_shard/releases/latest
[license]: LICENSE
8 changes: 8 additions & 0 deletions expected/queries.out
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,11 @@ SELECT author_id, sum(word_count) AS corpus_size FROM articles
6 | 50867
(5 rows)

-- verify temp tables used by cross-shard queries do not persist
SELECT COUNT(*) FROM pg_class WHERE relname LIKE 'pg_shard_temp_table%' AND
relkind = 'r';
count
-------
0
(1 row)

8 changes: 4 additions & 4 deletions expected/repair_shards.out.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ INSERT INTO pgs_distribution_metadata.shard_placement
(id, node_name, node_port, shard_id, shard_state)
VALUES
(200, 'localhost', $PGPORT, 20, 1),
(201, 'localhost.', $PGPORT, 20, 3);
(201, '127.0.0.1', $PGPORT, 20, 3);
CREATE TABLE customer_engagements_20 ( LIKE customer_engagements );
\o /dev/null
SELECT 'customer_engagements_20'::regclass::oid AS shardoid;
\gset
\o
SELECT master_copy_shard_placement(20, 'localhost', $PGPORT, 'localhost.', $PGPORT);
SELECT master_copy_shard_placement(20, 'localhost', $PGPORT, '127.0.0.1', $PGPORT);
ERROR: shard placement repair not fully implemented
\o /dev/null
SELECT 'customer_engagements_20'::regclass::oid AS repairedoid;
Expand Down Expand Up @@ -47,7 +47,7 @@ INSERT INTO pgs_distribution_metadata.shard_placement
(id, node_name, node_port, shard_id, shard_state)
VALUES
(300, 'localhost', $PGPORT, 30, 1),
(301, 'localhost.', $PGPORT, 30, 3);
(301, '127.0.0.1', $PGPORT, 30, 3);
CREATE FOREIGN TABLE remote_engagements_30 (
id integer,
created_at date,
Expand All @@ -57,7 +57,7 @@ CREATE FOREIGN TABLE remote_engagements_30 (
SELECT 'remote_engagements_30'::regclass::oid AS shardoid;
\gset
\o
SELECT master_copy_shard_placement(30, 'localhost', $PGPORT, 'localhost.', $PGPORT);
SELECT master_copy_shard_placement(30, 'localhost', $PGPORT, '127.0.0.1', $PGPORT);
ERROR: shard placement repair not fully implemented
\o /dev/null
SELECT 'remote_engagements_30'::regclass::oid AS repairedoid;
Expand Down
1 change: 1 addition & 0 deletions pg_shard.c
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ CreateTemporaryTableLikeStmt(Oid sourceRelationId)
createStmt = makeNode(CreateStmt);
createStmt->relation = clonedRelation;
createStmt->tableElts = list_make1(tableLikeClause);
createStmt->oncommit = ONCOMMIT_DROP;

return createStmt;
}
Expand Down
2 changes: 1 addition & 1 deletion sql/create_shards.sql.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ SELECT master_create_worker_shards('foreign_table_to_distribute', 16, 1);

SELECT storage, min_value, max_value FROM pgs_distribution_metadata.shard
WHERE relation_id = 'foreign_table_to_distribute'::regclass
ORDER BY (min_value COLLATE "C") ASC;
ORDER BY (min_value COLLATE "C") ASC;
5 changes: 5 additions & 0 deletions sql/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,8 @@ SELECT author_id, sum(word_count) AS corpus_size FROM articles
HAVING sum(word_count) > 25000
ORDER BY sum(word_count) DESC
LIMIT 5;

-- verify temp tables used by cross-shard queries do not persist
SELECT COUNT(*) FROM pg_class WHERE relname LIKE 'pg_shard_temp_table%' AND
relkind = 'r';

8 changes: 4 additions & 4 deletions sql/repair_shards.sql.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ INSERT INTO pgs_distribution_metadata.shard_placement
(id, node_name, node_port, shard_id, shard_state)
VALUES
(200, 'localhost', $PGPORT, 20, 1),
(201, 'localhost.', $PGPORT, 20, 3);
(201, '127.0.0.1', $PGPORT, 20, 3);

CREATE TABLE customer_engagements_20 ( LIKE customer_engagements );

Expand All @@ -26,7 +26,7 @@ SELECT 'customer_engagements_20'::regclass::oid AS shardoid;
\gset
\o

SELECT master_copy_shard_placement(20, 'localhost', $PGPORT, 'localhost.', $PGPORT);
SELECT master_copy_shard_placement(20, 'localhost', $PGPORT, '127.0.0.1', $PGPORT);

\o /dev/null
SELECT 'customer_engagements_20'::regclass::oid AS repairedoid;
Expand Down Expand Up @@ -54,7 +54,7 @@ INSERT INTO pgs_distribution_metadata.shard_placement
(id, node_name, node_port, shard_id, shard_state)
VALUES
(300, 'localhost', $PGPORT, 30, 1),
(301, 'localhost.', $PGPORT, 30, 3);
(301, '127.0.0.1', $PGPORT, 30, 3);

CREATE FOREIGN TABLE remote_engagements_30 (
id integer,
Expand All @@ -67,7 +67,7 @@ SELECT 'remote_engagements_30'::regclass::oid AS shardoid;
\gset
\o

SELECT master_copy_shard_placement(30, 'localhost', $PGPORT, 'localhost.', $PGPORT);
SELECT master_copy_shard_placement(30, 'localhost', $PGPORT, '127.0.0.1', $PGPORT);

\o /dev/null
SELECT 'remote_engagements_30'::regclass::oid AS repairedoid;
Expand Down
18 changes: 17 additions & 1 deletion test/create_shards.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#include "nodes/pg_list.h"


/* local function forward declarations */
static int CompareStrings(const void *leftElement, const void *rightElement);


/* declarations for dynamic loading */
PG_FUNCTION_INFO_V1(sort_names);
PG_FUNCTION_INFO_V1(create_table_then_fail);
Expand All @@ -40,7 +44,7 @@ sort_names(PG_FUNCTION_ARGS)
char *second = PG_GETARG_CSTRING(1);
char *third = PG_GETARG_CSTRING(2);
List *nameList = SortList(list_make3(first, second, third),
(int (*)(const void *, const void *)) &strcmp);
(int (*)(const void *, const void *)) &CompareStrings);
StringInfo sortedNames = makeStringInfo();

ListCell *nameCell = NULL;
Expand Down Expand Up @@ -72,3 +76,15 @@ create_table_then_fail(PG_FUNCTION_ARGS)

PG_RETURN_BOOL(commandsExecuted);
}

/*
* A simple wrapper around strcmp suitable for use with SortList or qsort.
*/
static int
CompareStrings(const void *leftElement, const void *rightElement)
{
const char *leftString = *((const char **) leftElement);
const char *rightString = *((const char **) rightElement);

return strcmp(leftString, rightString);
}

0 comments on commit a3dc6d0

Please sign in to comment.