You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tajo.apache.org by jh...@apache.org on 2013/10/10 06:28:36 UTC
git commit: TAJO-241: Does not reconnect the meta store. (jinho)
Updated Branches:
refs/heads/master d7645252f -> 69a38eb3b
TAJO-241: Does not reconnect the meta store. (jinho)
Project: http://git-wip-us.apache.org/repos/asf/incubator-tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tajo/commit/69a38eb3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tajo/tree/69a38eb3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tajo/diff/69a38eb3
Branch: refs/heads/master
Commit: 69a38eb3b2e8b6d09616bb6ff90ca9fb532c66d2
Parents: d764525
Author: jinossy <ji...@gmail.com>
Authored: Thu Oct 10 13:26:55 2013 +0900
Committer: jinossy <ji...@gmail.com>
Committed: Thu Oct 10 13:26:55 2013 +0900
----------------------------------------------------------------------
CHANGES.txt | 2 +
.../tajo/catalog/store/AbstractDBStore.java | 60 ++++++++++++--------
.../apache/tajo/catalog/store/DerbyStore.java | 30 +++++-----
.../apache/tajo/catalog/store/MySQLStore.java | 4 +-
4 files changed, 56 insertions(+), 40 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/69a38eb3/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 14f935a..2ebad3c 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -193,6 +193,8 @@ Release 0.2.0 - unreleased
BUG FIXES
+ TAJO-241: Does not reconnect the meta store. (jinho)
+
TAJO-226: Can't use group by column alias. (hyunsik)
TAJO-203: Field delimiter does not work correctly. (jinho)
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/69a38eb3/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
index d6413f8..71e4dd0 100644
--- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
@@ -45,7 +45,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
protected final Log LOG = LogFactory.getLog(getClass());
protected Configuration conf;
protected String jdbcUri;
- protected Connection conn;
+ private Connection conn;
protected static final int VERSION = 1;
@@ -114,9 +114,23 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
return jdbcUri;
}
+ public Connection getConnection() throws SQLException{
+ boolean isValid = false;
+ try{
+ isValid = conn.isValid(100);
+ } catch (SQLException e){
+ }
+
+ if(!isValid){
+ CatalogUtil.closeSQLWrapper(conn);
+ conn = createConnection(conf);
+ }
+ return conn;
+ }
+
private int needUpgrade() throws SQLException {
String sql = "SELECT VERSION FROM " + TB_META;
- Statement stmt = conn.createStatement();
+ Statement stmt = getConnection().createStatement();
ResultSet res = stmt.executeQuery(sql);
if (!res.next()) { // if this db version is 0
@@ -129,7 +143,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
private void insertVersion() throws SQLException {
String sql = "INSERT INTO " + TB_META + " values (0)";
- Statement stmt = conn.createStatement();
+ Statement stmt = getConnection().createStatement();
stmt.executeUpdate(sql);
stmt.close();
}
@@ -142,7 +156,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
sql = "DROP INDEX idx_options_key";
LOG.info(sql);
- stmt = conn.createStatement();
+ stmt = getConnection().createStatement();
stmt.addBatch(sql);
sql =
@@ -173,14 +187,14 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
+ ")";
try {
- stmt = conn.createStatement();
+ stmt = getConnection().createStatement();
if (LOG.isDebugEnabled()) {
LOG.debug(sql);
}
stmt.executeUpdate(sql);
- stmt = conn.createStatement();
+ stmt = getConnection().createStatement();
sql = "SELECT TID from " + TB_TABLES + " WHERE " + C_TABLE_ID
+ " = '" + table.getName() + "'";
if (LOG.isDebugEnabled()) {
@@ -276,7 +290,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
boolean exist = false;
try {
- stmt = conn.createStatement();
+ stmt = getConnection().createStatement();
if (LOG.isDebugEnabled()) {
LOG.debug(sql.toString());
}
@@ -297,7 +311,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
String sql = null;
try {
- stmt = conn.createStatement();
+ stmt = getConnection().createStatement();
sql = "DELETE FROM " + TB_COLUMNS +
" WHERE " + C_TABLE_ID + " = '" + name + "'";
LOG.info(sql);
@@ -312,7 +326,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
sql = "DELETE FROM " + TB_OPTIONS +
" WHERE " + C_TABLE_ID + " = '" + name + "'";
LOG.info(sql);
- stmt = conn.createStatement();
+ stmt = getConnection().createStatement();
stmt.execute(sql);
} catch (SQLException se) {
throw new IOException(se);
@@ -324,7 +338,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
sql = "DELETE FROM " + TB_STATISTICS +
" WHERE " + C_TABLE_ID + " = '" + name + "'";
LOG.info(sql);
- stmt = conn.createStatement();
+ stmt = getConnection().createStatement();
stmt.execute(sql);
} catch (SQLException se) {
throw new IOException(se);
@@ -336,7 +350,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
sql = "DELETE FROM " + TB_TABLES +
" WHERE " + C_TABLE_ID + " = '" + name + "'";
LOG.info(sql);
- stmt = conn.createStatement();
+ stmt = getConnection().createStatement();
stmt.execute(sql);
} catch (SQLException se) {
throw new IOException(se);
@@ -363,7 +377,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
if (LOG.isDebugEnabled()) {
LOG.debug(sql);
}
- stmt = conn.createStatement();
+ stmt = getConnection().createStatement();
res = stmt.executeQuery(sql);
if (!res.next()) { // there is no table of the given name.
return null;
@@ -382,7 +396,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
String sql = "SELECT column_name, data_type, type_length from " + TB_COLUMNS
+ " WHERE " + C_TABLE_ID + "='" + name + "' ORDER by column_id asc";
- stmt = conn.createStatement();
+ stmt = getConnection().createStatement();
if (LOG.isDebugEnabled()) {
LOG.debug(sql);
}
@@ -411,7 +425,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
try {
String sql = "SELECT key_, value_ from " + TB_OPTIONS
+ " WHERE " + C_TABLE_ID + "='" + name + "'";
- stmt = conn.createStatement();
+ stmt = getConnection().createStatement();
if (LOG.isDebugEnabled()) {
LOG.debug(sql);
}
@@ -434,7 +448,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
if (LOG.isDebugEnabled()) {
LOG.debug(sql);
}
- stmt = conn.createStatement();
+ stmt = getConnection().createStatement();
res = stmt.executeQuery(sql);
if (res.next()) {
@@ -476,7 +490,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
List<String> tables = new ArrayList<String>();
try {
- stmt = conn.createStatement();
+ stmt = getConnection().createStatement();
if (LOG.isDebugEnabled()) {
LOG.debug(sql);
}
@@ -502,7 +516,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
PreparedStatement stmt = null;
try {
- stmt = conn.prepareStatement(sql);
+ stmt = getConnection().prepareStatement(sql);
stmt.setString(1, proto.getName());
stmt.setString(2, proto.getTableId());
stmt.setString(3, proto.getColumn().getColumnName());
@@ -534,7 +548,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
Statement stmt = null;
try {
- stmt = conn.createStatement();
+ stmt = getConnection().createStatement();
if (LOG.isDebugEnabled()) {
LOG.debug(sql);
}
@@ -559,7 +573,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
"SELECT index_name, " + C_TABLE_ID + ", column_name, data_type, "
+ "index_type, is_unique, is_clustered, is_ascending FROM indexes "
+ "where index_name = ?";
- stmt = conn.prepareStatement(sql);
+ stmt = getConnection().prepareStatement(sql);
stmt.setString(1, indexName);
if (LOG.isDebugEnabled()) {
LOG.debug(stmt.toString());
@@ -590,7 +604,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
"SELECT index_name, " + C_TABLE_ID + ", column_name, data_type, "
+ "index_type, is_unique, is_clustered, is_ascending FROM indexes "
+ "where " + C_TABLE_ID + " = ? AND column_name = ?";
- stmt = conn.prepareStatement(sql);
+ stmt = getConnection().prepareStatement(sql);
stmt.setString(1, tableName);
stmt.setString(2, columnName);
if (LOG.isDebugEnabled()) {
@@ -624,7 +638,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
boolean exist = false;
try {
- stmt = conn.prepareStatement(sql);
+ stmt = getConnection().prepareStatement(sql);
stmt.setString(1, indexName);
if (LOG.isDebugEnabled()) {
LOG.debug(sql);
@@ -654,7 +668,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
ResultSet res = null;
try {
- stmt = conn.prepareStatement(sql);
+ stmt = getConnection().prepareStatement(sql);
stmt.setString(1, tableName);
stmt.setString(2, columnName);
if (LOG.isDebugEnabled()) {
@@ -683,7 +697,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
String sql = "SELECT index_name, " + C_TABLE_ID + ", column_name, data_type, "
+ "index_type, is_unique, is_clustered, is_ascending FROM indexes "
+ "where " + C_TABLE_ID + "= ?";
- stmt = conn.prepareStatement(sql);
+ stmt = getConnection().prepareStatement(sql);
stmt.setString(1, tableName);
if (LOG.isDebugEnabled()) {
LOG.debug(sql);
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/69a38eb3/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/DerbyStore.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/DerbyStore.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/DerbyStore.java
index 21d8a02..a1377ab 100644
--- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/DerbyStore.java
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/DerbyStore.java
@@ -67,7 +67,7 @@ public class DerbyStore extends AbstractDBStore {
Statement stmt = null;
try {
// META
- stmt = conn.createStatement();
+ stmt = getConnection().createStatement();
String meta_ddl = "CREATE TABLE " + TB_META + " (version int NOT NULL)";
if (LOG.isDebugEnabled()) {
LOG.debug(meta_ddl);
@@ -222,7 +222,7 @@ public class DerbyStore extends AbstractDBStore {
ResultSet res = null;
try {
boolean found = false;
- res = conn.getMetaData().getTables(null, null, null,
+ res = getConnection().getMetaData().getTables(null, null, null,
new String [] {"TABLE"});
String resName;
@@ -247,7 +247,7 @@ public class DerbyStore extends AbstractDBStore {
ResultSet res = null;
try {
boolean found = false;
- res = conn.getMetaData().getTables(null, null, null,
+ res = getConnection().getMetaData().getTables(null, null, null,
new String [] {"TABLE"});
while(res.next() && !found) {
if (tableName.equals(res.getString("TABLE_NAME")))
@@ -275,7 +275,7 @@ public class DerbyStore extends AbstractDBStore {
wlock.lock();
try {
- stmt = conn.createStatement();
+ stmt = getConnection().createStatement();
if (LOG.isDebugEnabled()) {
LOG.debug(sql);
}
@@ -377,7 +377,7 @@ public class DerbyStore extends AbstractDBStore {
boolean exist = false;
rlock.lock();
try {
- stmt = conn.createStatement();
+ stmt = getConnection().createStatement();
if (LOG.isDebugEnabled()) {
LOG.debug(sql.toString());
}
@@ -399,7 +399,7 @@ public class DerbyStore extends AbstractDBStore {
String sql = null;
try {
wlock.lock();
- stmt = conn.createStatement();
+ stmt = getConnection().createStatement();
try {
sql = "DELETE FROM " + TB_COLUMNS +
" WHERE " + C_TABLE_ID + " = '" + name + "'";
@@ -457,7 +457,7 @@ public class DerbyStore extends AbstractDBStore {
try {
rlock.lock();
- stmt = conn.createStatement();
+ stmt = getConnection().createStatement();
try {
String sql =
@@ -584,7 +584,7 @@ public class DerbyStore extends AbstractDBStore {
List<String> tables = new ArrayList<String>();
rlock.lock();
try {
- stmt = conn.createStatement();
+ stmt = getConnection().createStatement();
if (LOG.isDebugEnabled()) {
LOG.debug(sql);
}
@@ -611,7 +611,7 @@ public class DerbyStore extends AbstractDBStore {
wlock.lock();
try {
- stmt = conn.prepareStatement(sql);
+ stmt = getConnection().prepareStatement(sql);
stmt.setString(1, proto.getName());
stmt.setString(2, proto.getTableId());
stmt.setString(3, proto.getColumn().getColumnName());
@@ -643,7 +643,7 @@ public class DerbyStore extends AbstractDBStore {
Statement stmt = null;
wlock.lock();
try {
- stmt = conn.createStatement();
+ stmt = getConnection().createStatement();
if (LOG.isDebugEnabled()) {
LOG.debug(sql);
}
@@ -669,7 +669,7 @@ public class DerbyStore extends AbstractDBStore {
"SELECT index_name, " + C_TABLE_ID + ", column_name, data_type, "
+ "index_type, is_unique, is_clustered, is_ascending FROM indexes "
+ "where index_name = ?";
- stmt = conn.prepareStatement(sql);
+ stmt = getConnection().prepareStatement(sql);
stmt.setString(1, indexName);
if (LOG.isDebugEnabled()) {
LOG.debug(stmt.toString());
@@ -701,7 +701,7 @@ public class DerbyStore extends AbstractDBStore {
"SELECT index_name, " + C_TABLE_ID + ", column_name, data_type, "
+ "index_type, is_unique, is_clustered, is_ascending FROM indexes "
+ "where " + C_TABLE_ID + " = ? AND column_name = ?";
- stmt = conn.prepareStatement(sql);
+ stmt = getConnection().prepareStatement(sql);
stmt.setString(1, tableName);
stmt.setString(2, columnName);
if (LOG.isDebugEnabled()) {
@@ -735,7 +735,7 @@ public class DerbyStore extends AbstractDBStore {
boolean exist = false;
rlock.lock();
try {
- stmt = conn.prepareStatement(sql);
+ stmt = getConnection().prepareStatement(sql);
stmt.setString(1, indexName);
if (LOG.isDebugEnabled()) {
LOG.debug(sql);
@@ -766,7 +766,7 @@ public class DerbyStore extends AbstractDBStore {
boolean exist = false;
rlock.lock();
try {
- stmt = conn.prepareStatement(sql);
+ stmt = getConnection().prepareStatement(sql);
stmt.setString(1, tableName);
stmt.setString(2, columnName);
if (LOG.isDebugEnabled()) {
@@ -796,7 +796,7 @@ public class DerbyStore extends AbstractDBStore {
String sql = "SELECT index_name, " + C_TABLE_ID + ", column_name, data_type, "
+ "index_type, is_unique, is_clustered, is_ascending FROM indexes "
+ "where " + C_TABLE_ID + "= ?";
- stmt = conn.prepareStatement(sql);
+ stmt = getConnection().prepareStatement(sql);
stmt.setString(1, tableName);
if (LOG.isDebugEnabled()) {
LOG.debug(sql);
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/69a38eb3/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MySQLStore.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MySQLStore.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MySQLStore.java
index c638205..25e5674 100644
--- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MySQLStore.java
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MySQLStore.java
@@ -51,7 +51,7 @@ public class MySQLStore extends AbstractDBStore {
protected void createBaseTable() throws SQLException {
// META
- Statement stmt = conn.createStatement();
+ Statement stmt = getConnection().createStatement();
String meta_ddl = "CREATE TABLE " + TB_META + " (version int NOT NULL)";
if (LOG.isDebugEnabled()) {
LOG.debug(meta_ddl);
@@ -141,7 +141,7 @@ public class MySQLStore extends AbstractDBStore {
protected boolean isInitialized() throws SQLException {
boolean found = false;
- ResultSet res = conn.getMetaData().getTables(null, null, null,
+ ResultSet res = getConnection().getMetaData().getTables(null, null, null,
new String[]{"TABLE"});
String resName;