Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add instance_extra table and related objects
This patch adds the table for storing the instance NUMA topology, as adding it on the model itself as a text field is thought to be bad for perfomance. We need to add it as scheduling based on it and tracking resources proves to be impossible otherwise as we would have to rely on re-calculating it from data stashed in system_metadata table, which is deemed even more inefficient if it needs to be done in a periodic task. We add the objects so that we can make sure that data is versioned, and the relevant database models methods and the migration for adding the table. Blueprint: virt-driver-numa-placement Change-Id: I724ed7089044177ec4fecdf4fdcefad96a2466b6
- Loading branch information
Showing
16 changed files
with
452 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
nova/db/sqlalchemy/migrate_repo/versions/252_add_instance_extra_table.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
|
||
from migrate import ForeignKeyConstraint | ||
from sqlalchemy import Column | ||
from sqlalchemy import DateTime | ||
from sqlalchemy import Index | ||
from sqlalchemy import Integer | ||
from sqlalchemy import MetaData | ||
from sqlalchemy import String | ||
from sqlalchemy import Table | ||
from sqlalchemy import Text | ||
|
||
|
||
def upgrade(migrate_engine): | ||
meta = MetaData() | ||
meta.bind = migrate_engine | ||
|
||
columns = [ | ||
(('created_at', DateTime), {}), | ||
(('updated_at', DateTime), {}), | ||
(('deleted_at', DateTime), {}), | ||
(('deleted', Integer), {}), | ||
(('id', Integer), dict(primary_key=True, nullable=False)), | ||
(('instance_uuid', String(length=36)), dict(nullable=False)), | ||
(('numa_topology', Text), dict(nullable=True)), | ||
] | ||
for prefix in ('', 'shadow_'): | ||
instances = Table(prefix + 'instances', meta, autoload=True) | ||
basename = prefix + 'instance_extra' | ||
if migrate_engine.has_table(basename): | ||
continue | ||
_columns = tuple([Column(*args, **kwargs) | ||
for args, kwargs in columns]) | ||
table = Table(basename, meta, *_columns, mysql_engine='InnoDB', | ||
mysql_charset='utf8') | ||
table.create() | ||
|
||
# Index | ||
instance_uuid_index = Index(basename + '_idx', | ||
table.c.instance_uuid) | ||
instance_uuid_index.create(migrate_engine) | ||
|
||
# Foreign key | ||
if not prefix: | ||
fkey_columns = [table.c.instance_uuid] | ||
fkey_refcolumns = [instances.c.uuid] | ||
instance_fkey = ForeignKeyConstraint( | ||
columns=fkey_columns, refcolumns=fkey_refcolumns) | ||
instance_fkey.create() | ||
|
||
|
||
def downgrade(migrate_engine): | ||
meta = MetaData() | ||
meta.bind = migrate_engine | ||
|
||
for prefix in ('', 'shadow_'): | ||
table_name = prefix + 'instance_extra' | ||
if migrate_engine.has_table(table_name): | ||
instance_extra = Table(table_name, meta, autoload=True) | ||
instance_extra.drop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.