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

Migrate stats columns from show to show_stats #1228

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion VERSION.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.21
0.22
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ public void activateJob(JobInterface job, JobState jobState) {
jobTotals[0] + jobTotals[1], layers.size(), job.getJobId());

getJdbcTemplate().update(
"UPDATE show SET int_frame_insert_count=int_frame_insert_count+?, int_job_insert_count=int_job_insert_count+1 WHERE pk_show=?",
"UPDATE show_stats SET int_frame_insert_count=int_frame_insert_count+?, int_job_insert_count=int_job_insert_count+1 WHERE pk_show=?",
jobTotals[0] + jobTotals[1], job.getShowId());

updateState(job, jobState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,15 @@ public ShowEntity getShowDetail(HostInterface host) {
private static final String INSERT_SHOW =
"INSERT INTO show (pk_show,str_name) VALUES (?,?)";

private static final String INSERT_SHOW_STATS =
"INSERT INTO show_stats " +
"(pk_show, int_frame_insert_count, int_job_insert_count, int_frame_success_count, int_frame_fail_count) " +
"VALUES (?, 0, 0, 0, 0)";

public void insertShow(ShowEntity show) {
show.id = SqlUtil.genKeyRandom();
getJdbcTemplate().update(INSERT_SHOW, show.id, show.name);
getJdbcTemplate().update(INSERT_SHOW_STATS, show.id);
}

private static final String SHOW_EXISTS =
Expand Down Expand Up @@ -169,6 +175,8 @@ public void delete(ShowInterface s) {
s.getShowId());
getJdbcTemplate().update("DELETE FROM show_alias WHERE pk_show=?",
s.getShowId());
getJdbcTemplate().update("DELETE FROM show_stats WHERE pk_show=?",
s.getShowId());
getJdbcTemplate().update("DELETE FROM show WHERE pk_show=?",
s.getShowId());
}
Expand Down Expand Up @@ -262,7 +270,7 @@ public void updateFrameCounters(ShowInterface s, int exitStatus) {
col = "int_frame_fail_count = int_frame_fail_count + 1";
}
getJdbcTemplate().update(
"UPDATE show SET " + col + " WHERE pk_show=?", s.getShowId());
"UPDATE show_stats SET " + col + " WHERE pk_show=?", s.getShowId());
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2059,7 +2059,21 @@ public Show mapRow(ResultSet rs, int rowNum) throws SQLException {

private static final String GET_SHOW =
"SELECT " +
"show.*," +
"show.pk_show," +
"show.str_name," +
"show.b_paused," +
"show.int_default_min_cores," +
"show.int_default_max_cores," +
"show.int_default_min_gpus," +
"show.int_default_max_gpus," +
"show.b_booking_enabled," +
"show.b_dispatch_enabled," +
"show.b_active," +
"show.str_comment_email," +
"show_stats.int_frame_insert_count," +
"show_stats.int_job_insert_count," +
"show_stats.int_frame_success_count," +
"show_stats.int_frame_fail_count," +
"COALESCE(vs_show_stat.int_pending_count,0) AS int_pending_count," +
"COALESCE(vs_show_stat.int_running_count,0) AS int_running_count," +
"COALESCE(vs_show_stat.int_dead_count,0) AS int_dead_count," +
Expand All @@ -2068,6 +2082,7 @@ public Show mapRow(ResultSet rs, int rowNum) throws SQLException {
"COALESCE(vs_show_stat.int_job_count,0) AS int_job_count " +
"FROM " +
"show " +
"JOIN show_stats ON (show.pk_show = show_stats.pk_show) " +
DiegoTavares marked this conversation as resolved.
Show resolved Hide resolved
"LEFT JOIN vs_show_stat ON (vs_show_stat.pk_show = show.pk_show) " +
"LEFT JOIN vs_show_resource ON (vs_show_resource.pk_show=show.pk_show) " +
"WHERE " +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
CREATE TABLE show_stats (
DiegoTavares marked this conversation as resolved.
Show resolved Hide resolved
pk_show VARCHAR(36) NOT NULL,
int_frame_insert_count BIGINT DEFAULT 0 NOT NULL,
int_job_insert_count BIGINT DEFAULT 0 NOT NULL,
int_frame_success_count BIGINT DEFAULT 0 NOT NULL,
int_frame_fail_count BIGINT DEFAULT 0 NOT NULL
);

INSERT INTO show_stats (
pk_show,
int_frame_insert_count,
int_job_insert_count,
int_frame_success_count,
int_frame_fail_count
) SELECT
pk_show,
int_frame_insert_count,
int_job_insert_count,
int_frame_success_count,
int_frame_fail_count
FROM show;

CREATE UNIQUE INDEX c_show_stats_pk ON show_stats (pk_show);
ALTER TABLE show_stats ADD CONSTRAINT c_show_stats_pk PRIMARY KEY
USING INDEX c_show_stats_pk;


-- Destructive changes. Please test changes above prior to executing this.
DiegoTavares marked this conversation as resolved.
Show resolved Hide resolved
ALTER TABLE show
DROP COLUMN int_frame_insert_count,
DROP COLUMN int_job_insert_count,
DROP COLUMN int_frame_success_count,
DROP COLUMN int_frame_fail_count;
4 changes: 3 additions & 1 deletion cuebot/src/main/resources/conf/ddl/postgres/seed_data.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Insert into SHOW (PK_SHOW,STR_NAME,INT_DEFAULT_MAX_CORES,INT_DEFAULT_MIN_CORES,INT_FRAME_INSERT_COUNT,INT_JOB_INSERT_COUNT,INT_FRAME_SUCCESS_COUNT,INT_FRAME_FAIL_COUNT,B_BOOKING_ENABLED,B_DISPATCH_ENABLED,B_ACTIVE) values ('00000000-0000-0000-0000-000000000000', 'testing', 200000, 100, 0, 0, 0, 0, true, true, true);
Insert into SHOW (PK_SHOW,STR_NAME,INT_DEFAULT_MAX_CORES,INT_DEFAULT_MIN_CORES,B_BOOKING_ENABLED,B_DISPATCH_ENABLED,B_ACTIVE) values ('00000000-0000-0000-0000-000000000000', 'testing', 200000, 100, true, true, true);

Insert into SHOW_STATS (PK_SHOW,INT_FRAME_INSERT_COUNT,INT_JOB_INSERT_COUNT,INT_FRAME_SUCCESS_COUNT,INT_FRAME_FAIL_COUNT) values ('00000000-0000-0000-0000-000000000000',0,0,0,0)

Insert into SHOW_ALIAS (PK_SHOW_ALIAS,PK_SHOW,STR_NAME) values ('00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000000', 'test');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,20 +219,20 @@ public void testUpdateActive() {
public void testUpdateFrameCounters() {
ShowEntity show = showDao.findShowDetail(SHOW_NAME);
int frameSuccess = jdbcTemplate.queryForObject(
"SELECT int_frame_success_count FROM show WHERE pk_show=?",
"SELECT int_frame_success_count FROM show_stats WHERE pk_show=?",
Integer.class, show.id);
showDao.updateFrameCounters(show, 0);
int frameSucces2 = jdbcTemplate.queryForObject(
"SELECT int_frame_success_count FROM show WHERE pk_show=?",
"SELECT int_frame_success_count FROM show_stats WHERE pk_show=?",
Integer.class, show.id);
assertEquals(frameSuccess + 1,frameSucces2);

int frameFail= jdbcTemplate.queryForObject(
"SELECT int_frame_fail_count FROM show WHERE pk_show=?",
"SELECT int_frame_fail_count FROM show_stats WHERE pk_show=?",
Integer.class, show.id);
showDao.updateFrameCounters(show, 1);
int frameFail2 = jdbcTemplate.queryForObject(
"SELECT int_frame_fail_count FROM show WHERE pk_show=?",
"SELECT int_frame_fail_count FROM show_stats WHERE pk_show=?",
Integer.class, show.id);
assertEquals(frameFail+ 1,frameFail2);
}
Expand Down
8 changes: 6 additions & 2 deletions cuebot/src/test/resources/conf/ddl/postgres/test_data.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Insert into SHOW (PK_SHOW,STR_NAME,INT_DEFAULT_MAX_CORES,INT_DEFAULT_MIN_CORES,INT_FRAME_INSERT_COUNT,INT_JOB_INSERT_COUNT,INT_FRAME_SUCCESS_COUNT,INT_FRAME_FAIL_COUNT,B_BOOKING_ENABLED,B_DISPATCH_ENABLED,B_ACTIVE) values ('00000000-0000-0000-0000-000000000000','pipe',20000,100,0,0,0,0,true,true,true)
Insert into SHOW (PK_SHOW,STR_NAME,INT_DEFAULT_MAX_CORES,INT_DEFAULT_MIN_CORES,B_BOOKING_ENABLED,B_DISPATCH_ENABLED,B_ACTIVE) values ('00000000-0000-0000-0000-000000000000','pipe',20000,100,true,true,true)

Insert into SHOW (PK_SHOW,STR_NAME,INT_DEFAULT_MAX_CORES,INT_DEFAULT_MIN_CORES,INT_FRAME_INSERT_COUNT,INT_JOB_INSERT_COUNT,INT_FRAME_SUCCESS_COUNT,INT_FRAME_FAIL_COUNT,B_BOOKING_ENABLED,B_DISPATCH_ENABLED,B_ACTIVE) values ('00000000-0000-0000-0000-000000000001','edu',20000,100,0,0,0,0,true,true,true)
Insert into SHOW (PK_SHOW,STR_NAME,INT_DEFAULT_MAX_CORES,INT_DEFAULT_MIN_CORES,B_BOOKING_ENABLED,B_DISPATCH_ENABLED,B_ACTIVE) values ('00000000-0000-0000-0000-000000000001','edu',20000,100,true,true,true)

Insert into SHOW_STATS (PK_SHOW,INT_FRAME_INSERT_COUNT,INT_JOB_INSERT_COUNT,INT_FRAME_SUCCESS_COUNT,INT_FRAME_FAIL_COUNT) values ('00000000-0000-0000-0000-000000000000',0,0,0,0)

Insert into SHOW_STATS (PK_SHOW,INT_FRAME_INSERT_COUNT,INT_JOB_INSERT_COUNT,INT_FRAME_SUCCESS_COUNT,INT_FRAME_FAIL_COUNT) values ('00000000-0000-0000-0000-000000000001',0,0,0,0)


Insert into SHOW_ALIAS (PK_SHOW_ALIAS,PK_SHOW,STR_NAME) values ('00000000-0000-0000-0000-000000000001','00000000-0000-0000-0000-000000000000','fx')
Expand Down