You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@s2graph.apache.org by st...@apache.org on 2017/07/30 00:40:15 UTC
[2/3] incubator-s2graph git commit: add elementType on GlobalIndex.
add elementType on GlobalIndex.
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/ac7aac9c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/ac7aac9c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/ac7aac9c
Branch: refs/heads/master
Commit: ac7aac9c2d99ddfea149d4e012671a3ca77c73a4
Parents: 3725464
Author: DO YUNG YOON <st...@apache.org>
Authored: Sun Jul 30 09:09:39 2017 +0900
Committer: DO YUNG YOON <st...@apache.org>
Committed: Sun Jul 30 09:09:39 2017 +0900
----------------------------------------------------------------------
.travis.yml | 4 +--
dev_support/graph_mysql/schema.sql | 7 ++--
.../org/apache/s2graph/core/mysqls/schema.sql | 5 +--
.../org/apache/s2graph/core/Management.scala | 14 +++++---
.../s2graph/core/mysqls/GlobalIndex.scala | 38 ++++++++++++--------
5 files changed, 41 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ac7aac9c/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
index 7555a76..e50f9b8 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -16,7 +16,7 @@
language: scala
env:
- - HBASE_VERSION=1.2.5
+ - HBASE_VERSION=1.2.6
cache:
directories:
@@ -31,7 +31,7 @@ scala:
jdk:
- oraclejdk8
-sbt_args: -J-Xmx4G -J-Xms2G -J-Xss1M
+sbt_args: -J-Xmx2G -J-Xms1G -J-Xss1M
before_install:
- .travis/install-hbase.sh
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ac7aac9c/dev_support/graph_mysql/schema.sql
----------------------------------------------------------------------
diff --git a/dev_support/graph_mysql/schema.sql b/dev_support/graph_mysql/schema.sql
index 3c204a5..c8a4af8 100644
--- a/dev_support/graph_mysql/schema.sql
+++ b/dev_support/graph_mysql/schema.sql
@@ -120,22 +120,21 @@ CREATE TABLE `labels` (
ALTER TABLE labels add FOREIGN KEY(service_id) REFERENCES services(id);
-
-- ----------------------------
-- Table structure for `global_index`
-- ----------------------------
DROP TABLE IF EXISTS `global_indices`;
CREATE TABLE `global_indices` (
`id` integer NOT NULL AUTO_INCREMENT,
+ `element_type` varchar(64) NOT NULL,
`prop_names` varchar(255) NOT NULL,
`index_name` varchar(64) NOT NULL,
PRIMARY KEY (`id`),
- UNIQUE KEY `ux_global_index_index_name` (`index_name`),
- UNIQUE KEY `ux_global_index_prop_names` (`prop_names`)
+ UNIQUE KEY `ux_global_index_element_type_index_name` (`element_type`, `index_name`),
+ UNIQUE KEY `ux_global_index_element_type_prop_names` (`element_type`, `prop_names`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-
-- ----------------------------
-- Table structure for `label_metas`
-- ----------------------------
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ac7aac9c/s2core/src/main/resources/org/apache/s2graph/core/mysqls/schema.sql
----------------------------------------------------------------------
diff --git a/s2core/src/main/resources/org/apache/s2graph/core/mysqls/schema.sql b/s2core/src/main/resources/org/apache/s2graph/core/mysqls/schema.sql
index 521c9d2..f5f6a61 100644
--- a/s2core/src/main/resources/org/apache/s2graph/core/mysqls/schema.sql
+++ b/s2core/src/main/resources/org/apache/s2graph/core/mysqls/schema.sql
@@ -115,11 +115,12 @@ ALTER TABLE labels add FOREIGN KEY(service_id) REFERENCES services(id);
DROP TABLE IF EXISTS `global_indices`;
CREATE TABLE `global_indices` (
`id` integer NOT NULL AUTO_INCREMENT,
+ `element_type` varchar(64) NOT NULL,
`prop_names` varchar(255) NOT NULL,
`index_name` varchar(64) NOT NULL,
PRIMARY KEY (`id`),
- UNIQUE KEY `ux_global_index_index_name` (`index_name`),
- UNIQUE KEY `ux_global_index_prop_names` (`prop_names`)
+ UNIQUE KEY `ux_global_index_element_type_index_name` (`element_type`, `index_name`),
+ UNIQUE KEY `ux_global_index_element_type_prop_names` (`element_type`, `prop_names`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ac7aac9c/s2core/src/main/scala/org/apache/s2graph/core/Management.scala
----------------------------------------------------------------------
diff --git a/s2core/src/main/scala/org/apache/s2graph/core/Management.scala b/s2core/src/main/scala/org/apache/s2graph/core/Management.scala
index dc70cb8..3bb2179 100644
--- a/s2core/src/main/scala/org/apache/s2graph/core/Management.scala
+++ b/s2core/src/main/scala/org/apache/s2graph/core/Management.scala
@@ -348,11 +348,17 @@ class Management(graph: S2Graph) {
old.consistencyLevel, hTableName, old.hTableTTL, old.schemaVersion, old.isAsync, old.compressionAlgorithm, old.options)
}
- def buildGlobalIndex(name: String, propNames: Seq[String]): GlobalIndex = {
- GlobalIndex.findBy(name, false) match {
+ def buildGlobalVertexIndex(name: String, propNames: Seq[String]): GlobalIndex =
+ buildGlobalIndex(GlobalIndex.VertexType, name, propNames)
+
+ def buildGlobalEdgeIndex(name: String, propNames: Seq[String]): GlobalIndex =
+ buildGlobalIndex(GlobalIndex.EdgeType, name, propNames)
+
+ def buildGlobalIndex(elementType: String, name: String, propNames: Seq[String]): GlobalIndex = {
+ GlobalIndex.findBy(elementType, name, false) match {
case None =>
- GlobalIndex.insert(name, propNames)
- GlobalIndex.findBy(name, false).get
+ GlobalIndex.insert(elementType, name, propNames)
+ GlobalIndex.findBy(elementType, name, false).get
case Some(oldIndex) => oldIndex
}
}
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ac7aac9c/s2core/src/main/scala/org/apache/s2graph/core/mysqls/GlobalIndex.scala
----------------------------------------------------------------------
diff --git a/s2core/src/main/scala/org/apache/s2graph/core/mysqls/GlobalIndex.scala b/s2core/src/main/scala/org/apache/s2graph/core/mysqls/GlobalIndex.scala
index 1d1dfe2..a918db5 100644
--- a/s2core/src/main/scala/org/apache/s2graph/core/mysqls/GlobalIndex.scala
+++ b/s2core/src/main/scala/org/apache/s2graph/core/mysqls/GlobalIndex.scala
@@ -29,35 +29,40 @@ object GlobalIndex extends Model[GlobalIndex] {
val labelField = "_label_"
val serviceField = "_service_"
val serviceColumnField = "_serviceColumn_"
-
+ val EdgeType = "edge"
+ val VertexType = "vertex"
val hiddenIndexFields = Set(vidField, eidField, labelField, serviceField, serviceColumnField)
- val DefaultIndexName = GlobalIndex(None, Seq(vidField, eidField, serviceField, serviceColumnField, labelField), "_default_")
val TableName = "global_indices"
def apply(rs: WrappedResultSet): GlobalIndex = {
- GlobalIndex(rs.intOpt("id"), rs.string("prop_names").split(",").sorted, rs.string("index_name"))
+ GlobalIndex(rs.intOpt("id"),
+ rs.string("element_type"),
+ rs.string("prop_names").split(",").sorted,
+ rs.string("index_name"))
}
- def findBy(indexName: String, useCache: Boolean = true)(implicit session: DBSession = AutoSession): Option[GlobalIndex] = {
- val cacheKey = s"indexName=$indexName"
- lazy val sql = sql"""select * from global_indices where index_name = $indexName""".map { rs => GlobalIndex(rs) }.single.apply()
+ def findBy(elementType: String, indexName: String, useCache: Boolean = true)(implicit session: DBSession = AutoSession): Option[GlobalIndex] = {
+ val cacheKey = s"elementType=$elementType:indexName=$indexName"
+ lazy val sql = sql"""select * from global_indices where element_type = ${elementType} and index_name = $indexName""".map { rs => GlobalIndex(rs) }.single.apply()
+
if (useCache) withCache(cacheKey){sql}
else sql
}
- def insert(indexName: String, propNames: Seq[String])(implicit session: DBSession = AutoSession): Long = {
+ def insert(elementType: String, indexName: String, propNames: Seq[String])(implicit session: DBSession = AutoSession): Long = {
val allPropNames = (hiddenIndexFields.toSeq ++ propNames).sorted
- sql"""insert into global_indices(prop_names, index_name) values(${allPropNames.mkString(",")}, $indexName)"""
+ sql"""insert into global_indices(element_type, prop_names, index_name)
+ values($elementType, ${allPropNames.mkString(",")}, $indexName)"""
.updateAndReturnGeneratedKey.apply()
}
- def findAll(useCache: Boolean = true)(implicit session: DBSession = AutoSession): Seq[GlobalIndex] = {
- lazy val ls = sql"""select * from global_indices """.map { rs => GlobalIndex(rs) }.list.apply
+ def findAll(elementType: String, useCache: Boolean = true)(implicit session: DBSession = AutoSession): Seq[GlobalIndex] = {
+ lazy val ls = sql"""select * from global_indices where element_type = $elementType""".map { rs => GlobalIndex(rs) }.list.apply
if (useCache) {
- listCache.withCache("findAll") {
+ listCache.withCache(s"findAll:elementType=$elementType") {
putsToCache(ls.map { globalIndex =>
- val cacheKey = s"indexName=${globalIndex.indexName}"
+ val cacheKey = s"elementType=${globalIndex.elementType}:indexName=${globalIndex.indexName}"
cacheKey -> globalIndex
})
ls
@@ -67,9 +72,9 @@ object GlobalIndex extends Model[GlobalIndex] {
}
}
- def findGlobalIndex(hasContainers: java.util.List[HasContainer])(implicit session: DBSession = AutoSession): Option[GlobalIndex] = {
+ def findGlobalIndex(elementType: String, hasContainers: java.util.List[HasContainer])(implicit session: DBSession = AutoSession): Option[GlobalIndex] = {
import scala.collection.JavaConversions._
- val indices = findAll(useCache = true)
+ val indices = findAll(elementType, useCache = true)
val keys = hasContainers.map(_.getKey)
val sorted = indices.map { index =>
@@ -82,6 +87,9 @@ object GlobalIndex extends Model[GlobalIndex] {
}
-case class GlobalIndex(id: Option[Int], propNames: Seq[String], indexName: String) {
+case class GlobalIndex(id: Option[Int],
+ elementType: String,
+ propNames: Seq[String],
+ indexName: String) {
lazy val propNamesSet = propNames.toSet
}