Replace EventTotal Updates in zmstats.pl with triggers which will hold locks less. Move stats updates to zmaudit.pl
This commit is contained in:
parent
8e547134d5
commit
a7171eccf6
|
@ -229,17 +229,11 @@ CREATE TABLE `Events_Hour` (
|
||||||
) ENGINE=@ZM_MYSQL_ENGINE@;
|
) ENGINE=@ZM_MYSQL_ENGINE@;
|
||||||
|
|
||||||
delimiter //
|
delimiter //
|
||||||
DROP TRIGGER IF EXISTS Events_Hour_insert_trigger//
|
|
||||||
|
|
||||||
CREATE TRIGGER Events_Hour_insert_trigger AFTER INSERT ON Events_Hour
|
|
||||||
FOR EACH ROW BEGIN
|
|
||||||
UPDATE Monitors SET HourEvents = COALESCE(HourEvents,0)+1 WHERE Id=NEW.MonitorId;
|
|
||||||
END;
|
|
||||||
//
|
|
||||||
DROP TRIGGER IF EXISTS Events_Hour_delete_trigger//
|
DROP TRIGGER IF EXISTS Events_Hour_delete_trigger//
|
||||||
CREATE TRIGGER Events_Hour_delete_trigger BEFORE DELETE ON Events_Hour
|
CREATE TRIGGER Events_Hour_delete_trigger BEFORE DELETE ON Events_Hour
|
||||||
FOR EACH ROW BEGIN
|
FOR EACH ROW BEGIN
|
||||||
UPDATE Monitors SET HourEvents = COALESCE(HourEvents,1)-1,
|
UPDATE Monitors SET
|
||||||
|
HourEvents = COALESCE(HourEvents,1)-1,
|
||||||
HourEventDiskSpace=COALESCE(HourEventDiskSpace)-COALESCE(OLD.DiskSpace,0)
|
HourEventDiskSpace=COALESCE(HourEventDiskSpace)-COALESCE(OLD.DiskSpace,0)
|
||||||
WHERE Id=OLD.MonitorId;
|
WHERE Id=OLD.MonitorId;
|
||||||
END;
|
END;
|
||||||
|
@ -258,20 +252,12 @@ CREATE TABLE `Events_Day` (
|
||||||
) ENGINE=@ZM_MYSQL_ENGINE@;
|
) ENGINE=@ZM_MYSQL_ENGINE@;
|
||||||
|
|
||||||
delimiter //
|
delimiter //
|
||||||
DROP TRIGGER IF EXISTS Events_Day_insert_trigger//
|
|
||||||
CREATE TRIGGER Events_Day_insert_trigger AFTER INSERT ON Events_Day
|
|
||||||
FOR EACH ROW BEGIN
|
|
||||||
UPDATE Monitors SET
|
|
||||||
DayEvents = COALESCE(DayEvents,0)+1,
|
|
||||||
DayEventDiskSpace=COALESCE(DayEventDiskSpace)+COALESCE(NEW.DiskSpace,0)
|
|
||||||
WHERE Id=NEW.MonitorId;
|
|
||||||
END;
|
|
||||||
//
|
|
||||||
DROP TRIGGER IF EXISTS Events_Day_delete_trigger//
|
DROP TRIGGER IF EXISTS Events_Day_delete_trigger//
|
||||||
CREATE TRIGGER Events_Day_delete_trigger BEFORE DELETE ON Events_Day
|
CREATE TRIGGER Events_Day_delete_trigger BEFORE DELETE ON Events_Day
|
||||||
FOR EACH ROW BEGIN
|
FOR EACH ROW BEGIN
|
||||||
UPDATE Monitors SET DayEvents = COALESCE(DayEvents,1)-1,
|
UPDATE Monitors SET
|
||||||
DayEventDiskSpace=COALESCE(DayEventDiskSpace)-COALESCE(OLD.DiskSpace,0)
|
DayEvents = COALESCE(DayEvents,1)-1,
|
||||||
|
DayEventDiskSpace=COALESCE(DayEventDiskSpace,0)-COALESCE(OLD.DiskSpace,0)
|
||||||
WHERE Id=OLD.MonitorId;
|
WHERE Id=OLD.MonitorId;
|
||||||
END;
|
END;
|
||||||
//
|
//
|
||||||
|
@ -289,21 +275,12 @@ CREATE TABLE `Events_Week` (
|
||||||
) ENGINE=@ZM_MYSQL_ENGINE@;
|
) ENGINE=@ZM_MYSQL_ENGINE@;
|
||||||
|
|
||||||
delimiter //
|
delimiter //
|
||||||
DROP TRIGGER IF EXISTS Events_Week_insert_trigger//
|
|
||||||
CREATE TRIGGER Events_Week_insert_trigger AFTER INSERT ON Events_Week
|
|
||||||
FOR EACH ROW BEGIN
|
|
||||||
UPDATE Monitors SET
|
|
||||||
WeekEvents = COALESCE(WeekEvents,0)+1,
|
|
||||||
WeekEventDiskSpace=COALESCE(WeekEventDiskSpace)+COALESCE(NEW.DiskSpace,0)
|
|
||||||
WHERE Id=NEW.MonitorId;
|
|
||||||
END;
|
|
||||||
//
|
|
||||||
DROP TRIGGER IF EXISTS Events_Week_delete_trigger//
|
DROP TRIGGER IF EXISTS Events_Week_delete_trigger//
|
||||||
CREATE TRIGGER Events_Week_delete_trigger BEFORE DELETE ON Events_Week
|
CREATE TRIGGER Events_Week_delete_trigger BEFORE DELETE ON Events_Week
|
||||||
FOR EACH ROW BEGIN
|
FOR EACH ROW BEGIN
|
||||||
UPDATE Monitors SET
|
UPDATE Monitors SET
|
||||||
WeekEvents = COALESCE(WeekEvents,1)-1
|
WeekEvents = COALESCE(WeekEvents,1)-1,
|
||||||
WeekEventDiskSpace=COALESCE(WeekEventDiskSpace)-COALESCE(OLD.DiskSpace,0)
|
WeekEventDiskSpace=COALESCE(WeekEventDiskSpace,0)-COALESCE(OLD.DiskSpace,0)
|
||||||
WHERE Id=OLD.MonitorId;
|
WHERE Id=OLD.MonitorId;
|
||||||
END;
|
END;
|
||||||
//
|
//
|
||||||
|
@ -322,21 +299,12 @@ CREATE TABLE `Events_Month` (
|
||||||
) ENGINE=@ZM_MYSQL_ENGINE@;
|
) ENGINE=@ZM_MYSQL_ENGINE@;
|
||||||
|
|
||||||
delimiter //
|
delimiter //
|
||||||
DROP TRIGGER IF EXISTS Events_Month_insert_trigger//
|
|
||||||
create trigger Events_Month_insert_trigger after insert on Events_Month
|
|
||||||
FOR EACH ROW BEGIN
|
|
||||||
UPDATE Monitors SET
|
|
||||||
MonthEvents = COALESCE(MonthEvents,0)+1,
|
|
||||||
MonthEventDiskSpace=COALESCE(MonthEventDiskSpace)+COALESCE(NEW.DiskSpace,0)
|
|
||||||
WHERE Id=NEW.MonitorId;
|
|
||||||
END;
|
|
||||||
//
|
|
||||||
DROP TRIGGER IF EXISTS Events_Month_delete_trigger//
|
DROP TRIGGER IF EXISTS Events_Month_delete_trigger//
|
||||||
CREATE TRIGGER Events_Month_delete_trigger BEFORE DELETE ON Events_Month
|
CREATE TRIGGER Events_Month_delete_trigger BEFORE DELETE ON Events_Month
|
||||||
FOR EACH ROW BEGIN
|
FOR EACH ROW BEGIN
|
||||||
UPDATE Monitors SET
|
UPDATE Monitors SET
|
||||||
MonthEvents = COALESCE(MonthEvents,1)-1
|
MonthEvents = COALESCE(MonthEvents,1)-1,
|
||||||
MonthEventDiskSpace=COALESCE(MonthEventDiskSpace)-COALESCE(OLD.DiskSpace,0)
|
MonthEventDiskSpace=COALESCE(MonthEventDiskSpace,0)-COALESCE(OLD.DiskSpace,0)
|
||||||
WHERE Id=OLD.MonitorId;
|
WHERE Id=OLD.MonitorId;
|
||||||
END;
|
END;
|
||||||
//
|
//
|
||||||
|
@ -429,9 +397,9 @@ delimiter //
|
||||||
/* The assumption is that when an Event is inserted, it has no size yet, so don't bother updating the DiskSpace, just the count.
|
/* The assumption is that when an Event is inserted, it has no size yet, so don't bother updating the DiskSpace, just the count.
|
||||||
* The DiskSpace will get update in the Event Update Trigger
|
* The DiskSpace will get update in the Event Update Trigger
|
||||||
*/
|
*/
|
||||||
create trigger event_insert_trigger after insert on Events
|
CREATE TRIGGER event_insert_trigger AFTER INSERT ON Events
|
||||||
for each row
|
FOR EACH ROW
|
||||||
begin
|
BEGIN
|
||||||
|
|
||||||
INSERT INTO Events_Hour (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0);
|
INSERT INTO Events_Hour (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0);
|
||||||
INSERT INTO Events_Day (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0);
|
INSERT INTO Events_Day (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0);
|
||||||
|
@ -441,21 +409,15 @@ for each row
|
||||||
HourEvents = COALESCE(DayEvents,0)+1,
|
HourEvents = COALESCE(DayEvents,0)+1,
|
||||||
DayEvents = COALESCE(DayEvents,0)+1,
|
DayEvents = COALESCE(DayEvents,0)+1,
|
||||||
WeekEvents = COALESCE(DayEvents,0)+1,
|
WeekEvents = COALESCE(DayEvents,0)+1,
|
||||||
MonthEvents = COALESCE(DayEvents,0)+1
|
MonthEvents = COALESCE(DayEvents,0)+1,
|
||||||
TotalEvents = COALESCE(TotalEvents,0)+1
|
TotalEvents = COALESCE(TotalEvents,0)+1
|
||||||
WHERE Id=NEW.MonitorId;
|
WHERE Id=NEW.MonitorId;
|
||||||
end;
|
END;
|
||||||
//
|
//
|
||||||
|
|
||||||
delimiter ;
|
DROP TRIGGER IF EXISTS event_delete_trigger//
|
||||||
|
|
||||||
|
|
||||||
drop trigger if exists event_delete_trigger;
|
|
||||||
|
|
||||||
delimiter //
|
|
||||||
|
|
||||||
CREATE TRIGGER event_delete_trigger BEFORE DELETE ON Events
|
CREATE TRIGGER event_delete_trigger BEFORE DELETE ON Events
|
||||||
|
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
call update_storage_stats(OLD.StorageId, -OLD.DiskSpace);
|
call update_storage_stats(OLD.StorageId, -OLD.DiskSpace);
|
||||||
|
|
Loading…
Reference in New Issue