Skip to content

Commit c69feee

Browse files
committed
Fix the case where a incompleted record has no EndTime
- this probably slipped through before because of the lax type checking which we have now improved. - The RecordCreateTime for such records was would have been set to 'None' in the python code, rather None (or NULL in the mysql code, resulting in a load error as RecordCreateTime is non null.
1 parent fa42a5e commit c69feee

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

schemas/cloud.sql

+6-2
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,21 @@ CREATE PROCEDURE ReplaceCloudRecord(
8383
BEGIN
8484
DECLARE measurementTimeCalculated DATETIME;
8585
DECLARE recordCreateTimeNotNull DATETIME;
86+
DECLARE endTimeNotNull DATETIME;
8687

8788
IF(status='completed') THEN
8889
-- in this case, the recordCreateTime and measurementTime could
8990
-- be wildly different as the VM has ended.
9091

9192
-- if we werent supplied a record create time
9293
-- for a completed VM we have decided to use the end time
93-
SET recordCreateTimeNotNull = IF(recordCreateTime IS NULL or recordCreateTime='0000-00-00 00:00:00', endTime, recordCreateTime);
94+
-- We have to check the EndTime is not null because we can't guarantee this as we
95+
-- previously loaded completed messages with no EndTime.
96+
SET endTimeNotNull = IFNULL(endTime, '0000-00-00 00:00:00');
97+
SET recordCreateTimeNotNull = IF(recordCreateTime IS NULL or recordCreateTime='0000-00-00 00:00:00', endTimeNotNull, recordCreateTime);
9498

9599
-- Use the end time as the measurement time
96-
SET measurementTimeCalculated = endTime;
100+
SET measurementTimeCalculated = endTimeNotNull;
97101

98102
ELSE
99103
-- In the case of a running VM, the measurement time will

scripts/update_measurememt_time.sql

+6-2
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,21 @@ CREATE PROCEDURE ReplaceCloudRecord(
3333
BEGIN
3434
DECLARE measurementTimeCalculated DATETIME;
3535
DECLARE recordCreateTimeNotNull DATETIME;
36+
DECLARE endTimeNotNull DATETIME;
3637

3738
IF(status='completed') THEN
3839
-- in this case, the recordCreateTime and measurementTime could
3940
-- be wildly different as the VM has ended.
4041

4142
-- if we werent supplied a record create time
4243
-- for a completed VM we have decided to use the end time
43-
SET recordCreateTimeNotNull = IF(recordCreateTime IS NULL or recordCreateTime='0000-00-00 00:00:00', endTime, recordCreateTime);
44+
-- We have to check the EndTime is not null because we can't guarantee this as we
45+
-- previously loaded completed messages with no EndTime.
46+
SET endTimeNotNull = IFNULL(endTime, '0000-00-00 00:00:00');
47+
SET recordCreateTimeNotNull = IF(recordCreateTime IS NULL or recordCreateTime='0000-00-00 00:00:00', endTimeNotNull, recordCreateTime);
4448

4549
-- Use the end time as the measurement time
46-
SET measurementTimeCalculated = endTime;
50+
SET measurementTimeCalculated = endTimeNotNull;
4751

4852
ELSE
4953
-- In the case of a running VM, the measurement time will

0 commit comments

Comments
 (0)