Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing constraints on cloud resource specifications tables to prevent extra rows #1511

Merged
merged 5 commits into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions classes/OpenXdmod/Migration/Version900To950/DatabaseMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use CCR\DB;
use ETL\Utilities;
use OpenXdmod\Setup\Console;

/**
* Migrate databases from version 9.0.0 to 9.5.0.
Expand All @@ -17,9 +18,34 @@ public function execute()
{
parent::execute();

$console = Console::factory();

$dbh = DB::factory('datawarehouse');
$mysql_helper = \CCR\DB\MySQLHelper::factory($dbh);
if ($mysql_helper->tableExists('modw_cloud.cloud_resource_specs')) {

$staging_resource_sql = "SELECT
COUNT(*)
FROM
modw_cloud.staging_resource_specifications
GROUP BY
resource_id, hostname, fact_date
HAVING
COUNT(*) > 1";

$staging_result = $dbh->query($staging_resource_sql);

if(count($staging_result) > 0) {
$console->displayMessage(<<<"EOT"
This version of Open XDMoD changes the schema on two tables related to cloud utilization metrics. It appears that
data in the table modw_cloud.staging_resource_specifications will violate these schema changes. The violation is that
there cannot be two rows with the same resource ID, hostname, and date. Before you next ingest your cloud resource
specification files you should either remove any extra rows or truncate this table and then shred and ingest all of
your cloud resource specification files.
EOT
);
}

Utilities::runEtlPipeline(
['cloud-migration-9_0_0-9_5_0'],
$this->logger,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"#": "Record types are global to all cloud resources",
"#": "Contains the start and end time for a specific set of vcpus and memory for a cloud host.",

"table_definition": {
"name": "cloud_resource_specs",
"engine": "MyISAM",
"comment": "Record type: accounting, administrative, derived, etc.",
"comment": "Contains the start and end time for a specific set of vcpus and memory for a cloud host",
"columns": [
{
"name": "host_id",
Expand Down Expand Up @@ -62,20 +62,13 @@
"extra": "on update CURRENT_TIMESTAMP"
}
],

"#": "Note that the primary key is (resource, type, identifier, create_time) rather than",
"#": "asset_id so we can take advantage of ON DUPLICATE KEY UPDATE to update existing entries",
"#": "and still use auto_increment for new entries.",

"indexes": [
{
"name": "PRIMARY",
"columns": [
"resource_id",
"hostname",
"memory_mb",
"vcpus",
"start_date_ts"
"start_day_id"
],
"is_unique": true
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"#": "Record types are global to all cloud resources",
"#": "This table contains a specific set of vcpus and memory size for a host for",
"#": "a day. There should be no more than one record for a host on a day.",

"table_definition": {
"name": "staging_resource_specifications",
"engine": "MyISAM",
"comment": "Record type: accounting, administrative, derived, etc.",
"comment": "Contains a specific set of vcpus and memory size for a host for a day",
"columns": [
{
"name": "hostname",
Expand Down Expand Up @@ -42,8 +43,6 @@
"columns": [
"resource_id",
"hostname",
"memory_mb",
"vcpus",
"fact_date"
],
"is_unique": true
Expand Down