π ν΄λΉ ν¬μ€ν μ λͺ©ν
- Spring Batch DB μ€ν€λ§ λΆμ
π Spring Batch DB μ€ν€λ§
μ§λ μκ°μλ Spring Batchμ κ°μ λ° νλ‘μ νΈ κ΅¬μ±, μΈν λ° κ°λ¨ν Job μ€νμ λν΄ μ΄ν΄λ³΄μμ΅λλ€.
μ΄λ² μκ°μλ Spring Batchμ Meta Data Schemaμ λν΄ μ΄ν΄λ³΄κ² μ΅λλ€.
Meta Data Schema
- μ€νλ§ λ°°μΉμ μ€ν λ° κ΄λ¦¬λ₯Ό μν λͺ©μ μΌλ‘ μ¬λ¬ λλ©μΈλ€(Job, Step, JobParameters λ±)μ λν μ 보λ₯Ό μ μ₯, μ λ°μ΄νΈ, μ‘°ν λ±μ μμ μ ν μ μλ μ€ν€λ§ μ 곡
- κ³Όκ±° λ° νμ¬μ Batch μ€νμ λν μ 보(μ±κ³΅, μ€ν¨ μ¬λΆ)λ₯Ό κ΄λ¦¬ν¨μΌλ‘μ λ°°μΉμ΄μ λ° μ₯μ μ κ΄λ ¨λ λμ² κ°λ₯
- DBμ μ°λν κ²½μ° νμμ μΌλ‘ λ©ν ν μ΄λΈμ΄ μμ±λμ΄μΌ ν¨
DB μ€ν€λ§ μ 보
spring-batch-core λΌμ΄λΈλ¬λ¦¬μ λ΄λΆμ schema-*.sql νμΌμ λ°μ΄ν°λ² μ΄μ€ λ³ λ©ν λ°μ΄ν° μ€ν€λ§κ° μ‘΄μ¬ν©λλ€.
λνμ μΌλ‘ schema-mysql.sql νμΌμ μμ±λμ΄ μλ ν μ΄λΈμ λν μ 보λ λ€μκ³Ό κ°μ΅λλ€.
(λ°μ΄ν°λ² μ΄μ€μ λ°λΌ 쿼리λ μΌλΆ λ€λ¦ λλ€.)
-- Autogenerated: do not edit this file
CREATE TABLE BATCH_JOB_INSTANCE (
JOB_INSTANCE_ID BIGINT NOT NULL PRIMARY KEY ,
VERSION BIGINT ,
JOB_NAME VARCHAR(100) NOT NULL,
JOB_KEY VARCHAR(32) NOT NULL,
constraint JOB_INST_UN unique (JOB_NAME, JOB_KEY)
) ENGINE=InnoDB;
CREATE TABLE BATCH_JOB_EXECUTION (
JOB_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY ,
VERSION BIGINT ,
JOB_INSTANCE_ID BIGINT NOT NULL,
CREATE_TIME DATETIME(6) NOT NULL,
START_TIME DATETIME(6) DEFAULT NULL ,
END_TIME DATETIME(6) DEFAULT NULL ,
STATUS VARCHAR(10) ,
EXIT_CODE VARCHAR(2500) ,
EXIT_MESSAGE VARCHAR(2500) ,
LAST_UPDATED DATETIME(6),
JOB_CONFIGURATION_LOCATION VARCHAR(2500) NULL,
constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID)
references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID)
) ENGINE=InnoDB;
CREATE TABLE BATCH_JOB_EXECUTION_PARAMS (
JOB_EXECUTION_ID BIGINT NOT NULL ,
TYPE_CD VARCHAR(6) NOT NULL ,
KEY_NAME VARCHAR(100) NOT NULL ,
STRING_VAL VARCHAR(250) ,
DATE_VAL DATETIME(6) DEFAULT NULL ,
LONG_VAL BIGINT ,
DOUBLE_VAL DOUBLE PRECISION ,
IDENTIFYING CHAR(1) NOT NULL ,
constraint JOB_EXEC_PARAMS_FK foreign key (JOB_EXECUTION_ID)
references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID)
) ENGINE=InnoDB;
CREATE TABLE BATCH_STEP_EXECUTION (
STEP_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY ,
VERSION BIGINT NOT NULL,
STEP_NAME VARCHAR(100) NOT NULL,
JOB_EXECUTION_ID BIGINT NOT NULL,
START_TIME DATETIME(6) NOT NULL ,
END_TIME DATETIME(6) DEFAULT NULL ,
STATUS VARCHAR(10) ,
COMMIT_COUNT BIGINT ,
READ_COUNT BIGINT ,
FILTER_COUNT BIGINT ,
WRITE_COUNT BIGINT ,
READ_SKIP_COUNT BIGINT ,
WRITE_SKIP_COUNT BIGINT ,
PROCESS_SKIP_COUNT BIGINT ,
ROLLBACK_COUNT BIGINT ,
EXIT_CODE VARCHAR(2500) ,
EXIT_MESSAGE VARCHAR(2500) ,
LAST_UPDATED DATETIME(6),
constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID)
references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID)
) ENGINE=InnoDB;
CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT (
STEP_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY,
SHORT_CONTEXT VARCHAR(2500) NOT NULL,
SERIALIZED_CONTEXT TEXT ,
constraint STEP_EXEC_CTX_FK foreign key (STEP_EXECUTION_ID)
references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID)
) ENGINE=InnoDB;
CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT (
JOB_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY,
SHORT_CONTEXT VARCHAR(2500) NOT NULL,
SERIALIZED_CONTEXT TEXT ,
constraint JOB_EXEC_CTX_FK foreign key (JOB_EXECUTION_ID)
references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID)
) ENGINE=InnoDB;
CREATE TABLE BATCH_STEP_EXECUTION_SEQ (
ID BIGINT NOT NULL,
UNIQUE_KEY CHAR(1) NOT NULL,
constraint UNIQUE_KEY_UN unique (UNIQUE_KEY)
) ENGINE=InnoDB;
INSERT INTO BATCH_STEP_EXECUTION_SEQ (ID, UNIQUE_KEY) select * from (select 0 as ID, '0' as UNIQUE_KEY) as tmp where not exists(select * from BATCH_STEP_EXECUTION_SEQ);
CREATE TABLE BATCH_JOB_EXECUTION_SEQ (
ID BIGINT NOT NULL,
UNIQUE_KEY CHAR(1) NOT NULL,
constraint UNIQUE_KEY_UN unique (UNIQUE_KEY)
) ENGINE=InnoDB;
INSERT INTO BATCH_JOB_EXECUTION_SEQ (ID, UNIQUE_KEY) select * from (select 0 as ID, '0' as UNIQUE_KEY) as tmp where not exists(select * from BATCH_JOB_EXECUTION_SEQ);
CREATE TABLE BATCH_JOB_SEQ (
ID BIGINT NOT NULL,
UNIQUE_KEY CHAR(1) NOT NULL,
constraint UNIQUE_KEY_UN unique (UNIQUE_KEY)
) ENGINE=InnoDB;
INSERT INTO BATCH_JOB_SEQ (ID, UNIQUE_KEY) select * from (select 0 as ID, '0' as UNIQUE_KEY) as tmp where not exists(select * from BATCH_JOB_SEQ);
MySQLμ κ²½μ° Job, Step κ΄λ ¨ 6κ°μ ν μ΄λΈκ³Ό 3κ°μ μνμ€μ λν ν μ΄λΈμ μμ±ν©λλ€.
- Job: BATCH_JOB_INSTANCE, BATCH_JOB_EXECUTION, BATCH_JOB_EXECUTION_PARAMS, BATCH_JOB_EXECUTION_CONTEXT
- Step: BATCH_STEP_EXECUTION, BATCH_STEP_EXECUTION_CONTEXT
- Seq: BATCH_JOB_SEQ, BATCH_JOB_EXECUTION_SEQ, BATCH_STEP_EXECUTION_SEQ
μ€ν€λ§ μμ± μ€μ
λ°μ΄ν°λ² μ΄μ€ μ€ν€λ§λ μλ λ° μλμΌλ‘ μμ±ν μ μμ΅λλ€.
(μ΄μμμλ μλμΌλ‘ μ€ν¬λ¦½νΈλ₯Ό μμ±νμ¬ μ€μ νλ κ²μ κΆμ₯ν©λλ€.)
- μλ μμ±: μ schema-*.sql νμΌμ μμ±λ 쿼리λ₯Ό 볡μ¬νμ¬ μ§μ μ€ν
- μλ μμ±: spring.batch.jdbc.initialize-schema μ€μ
- ALWAYS: μ€ν¬λ¦½νΈλ₯Ό νμ μ€ν
- EMBEDDED: λ΄μ₯ DBμΌ λλ§ μ€νλλ©° μ€ν€λ§κ° μλ μμ±(default)
- NEVER: μ€ν¬λ¦½νΈ μ€ν X
MetaData Schema
BATCH_JOB_INSTANCE
- Jobμ΄ μ€νλ λ JobInstance μ λ³΄κ° μ μ₯
- μ€νλλ Jobμ Name, Keyμ λν λ°μ΄ν°λ₯Ό μ μ₯
BATCH_JOB_EXECUTION
- Jobμ μ€ν μ λ³΄κ° μ μ₯λλ©° Jobμ μμ±, μμ, μ’ λ£ μκ°, μ€νμν, λ©μμ§ λ±μ κ΄λ¦¬
BATCH_JOB_EXECUTION_PARAMS
- Jobκ³Ό ν¨κ» μ€νλλ JobParameters μ 보λ₯Ό μ μ₯
BATCH_JOB_EXECUTION_CONTEXT
- Jobμ μ€νλμ μ¬λ¬ μνμ 보, 곡μ λ°μ΄ν°λ₯Ό μ§λ ¬ν(JSON)ν΄μ μ μ₯
- Step κ° λ°μ΄ν° 곡μ κ° κ°λ₯ν¨
BATCH_STEP_EXECUTION
- Stepμ μ€ν μ λ³΄κ° μ μ₯λλ©° Stepμ μμ±, μμ, μ’ λ£ μκ°, μ€νμν, λ©μμ§ λ±μ κ΄λ¦¬
BATCH_STEP_EXECUTION_CONTEXT
- Stepμ μ€νλμ μ¬λ¬ μνμ 보, 곡μ λ°μ΄ν°λ₯Ό μ§λ ¬ν(JSON)ν΄μ μ μ₯
- Stepλ³λ‘ μ μ₯λλ©° Stepκ° λ°μ΄ν°λ₯Ό 곡μ ν μ μμ
κ° ν μ΄λΈμ λν 컬λΌμ PK, Name, μ€ν λ° μ’ λ£ μκ°, μν, μ’ λ£ μ½λ, VERSION(Optimistic Locking μ λ΅), μ€ν¨ λ©μμ§ λ±μ λν λ°μ΄ν°λ₯Ό μ μ₯νλλ°μ, 컬λΌμ λν μ€λͺ μ 곡μλ¬Έμμ μμΈν λμμμ΅λλ€.
π μ°Έκ³ λ¬Έμ
- https://docs.spring.io/spring-batch/docs/current/reference/html/schema-appendix.html
- https://www.inflearn.com/course/%EC%8A%A4%ED%94%84%EB%A7%81-%EB%B0%B0%EC%B9%98/dashboard
'Spring > Spring Batch' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
Spring Batch (6) ExecutionContext (0) | 2022.11.05 |
---|---|
Spring Batch (5) Step, StepExecution (0) | 2022.11.03 |
Spring Batch (4) Job, JobInstance, JobParameters, JobExecution (0) | 2022.11.01 |
Spring Batch (2) νλ‘μ νΈ κ΅¬μ± λ° μμ‘΄μ± μ€μ , Hello World (0) | 2022.10.29 |
Spring Batch (1) κ°μ (0) | 2022.10.28 |
λκΈ