[HBase] Catch AlreadyExists error in Connection upgrade
Now in upstream, if HBase table exists when we upgrade backend AlreadyExists exception is raised. Also exception raising interrupts creating of other tables. It is an incorrect behavior because we should create all tables and migrate them if need or use existing tables. Change-Id: I8e8a8ae633351de8393b5103910510dd635245be Closes: bug #1370508
This commit is contained in:
parent
7b89798be3
commit
5e8fb13dbb
@ -98,9 +98,10 @@ class Connection(base.Connection):
|
|||||||
self.conn_pool = self._get_connection_pool(opts)
|
self.conn_pool = self._get_connection_pool(opts)
|
||||||
|
|
||||||
def upgrade(self):
|
def upgrade(self):
|
||||||
|
tables = [self.ALARM_HISTORY_TABLE, self.ALARM_TABLE]
|
||||||
|
column_families = {'f': dict()}
|
||||||
with self.conn_pool.connection() as conn:
|
with self.conn_pool.connection() as conn:
|
||||||
conn.create_table(self.ALARM_TABLE, {'f': dict()})
|
hbase_utils.create_tables(conn, tables, column_families)
|
||||||
conn.create_table(self.ALARM_HISTORY_TABLE, {'f': dict()})
|
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
LOG.debug(_('Dropping HBase schema...'))
|
LOG.debug(_('Dropping HBase schema...'))
|
||||||
|
@ -17,9 +17,14 @@ import datetime
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
import bson.json_util
|
import bson.json_util
|
||||||
|
from happybase.hbase import ttypes
|
||||||
|
|
||||||
|
from ceilometer.openstack.common.gettextutils import _
|
||||||
|
from ceilometer.openstack.common import log
|
||||||
from ceilometer import utils
|
from ceilometer import utils
|
||||||
|
|
||||||
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
EVENT_TRAIT_TYPES = {'none': 0, 'string': 1, 'integer': 2, 'float': 3,
|
EVENT_TRAIT_TYPES = {'none': 0, 'string': 1, 'integer': 2, 'float': 3,
|
||||||
'datetime': 4}
|
'datetime': 4}
|
||||||
OP_SIGN = {'eq': '=', 'lt': '<', 'le': '<=', 'ne': '!=', 'gt': '>', 'ge': '>='}
|
OP_SIGN = {'eq': '=', 'lt': '<', 'le': '<=', 'ne': '!=', 'gt': '>', 'ge': '>='}
|
||||||
@ -416,3 +421,21 @@ def object_hook(dct):
|
|||||||
dt = bson.json_util.object_hook(dct)
|
dt = bson.json_util.object_hook(dct)
|
||||||
return dt.replace(tzinfo=None)
|
return dt.replace(tzinfo=None)
|
||||||
return bson.json_util.object_hook(dct)
|
return bson.json_util.object_hook(dct)
|
||||||
|
|
||||||
|
|
||||||
|
def create_tables(conn, tables, column_families):
|
||||||
|
for table in tables:
|
||||||
|
try:
|
||||||
|
conn.create_table(table, column_families)
|
||||||
|
except ttypes.AlreadyExists:
|
||||||
|
if conn.table_prefix:
|
||||||
|
table = ("%(table_prefix)s"
|
||||||
|
"%(separator)s"
|
||||||
|
"%(table_name)s" %
|
||||||
|
dict(table_prefix=conn.table_prefix,
|
||||||
|
separator=conn.table_prefix_separator,
|
||||||
|
table_name=table))
|
||||||
|
|
||||||
|
LOG.warn(_("Cannot create table %(table_name)s "
|
||||||
|
"it already exists. Ignoring error")
|
||||||
|
% {'table_name': table})
|
@ -161,10 +161,10 @@ class Connection(base.Connection):
|
|||||||
self.conn_pool = self._get_connection_pool(opts)
|
self.conn_pool = self._get_connection_pool(opts)
|
||||||
|
|
||||||
def upgrade(self):
|
def upgrade(self):
|
||||||
|
tables = [self.RESOURCE_TABLE, self.METER_TABLE, self.EVENT_TABLE]
|
||||||
|
column_families = {'f': dict(max_versions=1)}
|
||||||
with self.conn_pool.connection() as conn:
|
with self.conn_pool.connection() as conn:
|
||||||
conn.create_table(self.RESOURCE_TABLE, {'f': dict(max_versions=1)})
|
hbase_utils.create_tables(conn, tables, column_families)
|
||||||
conn.create_table(self.METER_TABLE, {'f': dict(max_versions=1)})
|
|
||||||
conn.create_table(self.EVENT_TABLE, {'f': dict(max_versions=1)})
|
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
LOG.debug(_('Dropping HBase schema...'))
|
LOG.debug(_('Dropping HBase schema...'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user