Skip to content

Commit f984a89

Browse files
Implement locking of indexed files. (#690)
* add: processUuid and processId * add: create a new table `file_lock` * refactor: suppress PMD warnings * fix: sql statement creating a new table `file_lock` * wip: wip * fix: a PMD warning * fix: a SpotBug warning * refactor: remove printStackTrace() * fix: check formats of indexed files to open * test: remove unnecessary checks * fix: change constants to avoid overlaps * fix: add a file existing check * test: fix the test of opening an invalid indexed file * test: fix load.at not to call default error handlers * chore: end a transaction * refactor: CobolIndexedFile.java * test: prevent infinite loops * refactor: CobolIndexedFile.java * wip: wip * fix: improve open_ in CobolIndexedFile.java * change: set transaction settings * set the transaction mode to EXCLUSIVE * set busy_timeout to 5000 * feat: implement file locks of indexed files * fix: change the condition of creating file_lock * change: set the transaction isolation to SERIALIZABLE * test: add tests of file locking of indexed files * change: the schema of the record key table * fix: an INSERT statement * fix: an insert statement for primary record tables * feat: add a new option `-default_select_lock_mode` * channge: insert information when calling read_() * fix: the method read_ * Implement file locking of indexed files (#678) * add: processUuid and processId * add: create a new table `file_lock` * refactor: suppress PMD warnings * fix: sql statement creating a new table `file_lock` * wip: wip * fix: a PMD warning * fix: a SpotBug warning * refactor: remove printStackTrace() * fix: check formats of indexed files to open * test: remove unnecessary checks * fix: change constants to avoid overlaps * fix: add a file existing check * test: fix the test of opening an invalid indexed file * test: fix load.at not to call default error handlers * chore: end a transaction * refactor: CobolIndexedFile.java * test: prevent infinite loops * refactor: CobolIndexedFile.java * wip: wip * fix: improve open_ in CobolIndexedFile.java * change: set transaction settings * set the transaction mode to EXCLUSIVE * set busy_timeout to 5000 * feat: implement file locks of indexed files * fix: change the condition of creating file_lock * change: set the transaction isolation to SERIALIZABLE * test: add tests of file locking of indexed files * Update libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolIndexedFile.java Co-authored-by: Copilot <[email protected]> * Update libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolIndexedFile.java Co-authored-by: Copilot <[email protected]> * refactor: remove unnecessary comments * refactor: fix typo * refactor: fix typo --------- Co-authored-by: Copilot <[email protected]> * refactor: CobolIndexedFile.java * add: lock a record when READ NEXT is executed * add: unlock records when closing indexed files * fix: the process of unlocking a file lock * fix: controling transactions when rewriting records * fix: commit timing when writing records * fix: commits and rollbacks in WRITE, REWRITE and DELETE * change: -default_lock_mode to -lock-mode-automatic * refactor: code for commiting data * add: unlock the previous record after writing * add: unlock previous records after rewriting * add: impelment record lockings of DELETE * fix: constant numbers change the value of COB_LOCK_AUTOMATIC and COB_LOCK_MULTIPLE in CobolFile.java * chore: remove duplicated code * fix: close ResultSet not to lock database implicitly * fix: close ResultSet in CobolIndexedFile.java * add: NewIndexedCursor.java * wip: read forward * wip: read prev * fix: fetchRecord * fix: READ NEXT/PREVIOUS * fix: READ * fix: fetchRecord * fix: fetchRecord * fix: START * fix: START ~ KEY IS GREATER THAN * fix: START ~ KEY IS <= * fix: START and READ NEXT RECORD * refactor: resolve PMD warnings * chore: migrate NewIndexedCursor to IndexedCursor * fix: allow READ WITH LOCK/WITH NO LOCK if LOCK MODE IS AUTOMATIC * fix: call commit() in the end of READ and READ NEXT/PREV * fix: initialize previousLockedReclordKey in close_() * test: add some tests for record locking * fix: unlock Previous records at the end of READ * test: accelerate file locking tests * test: wip * test: add tests for `READ WITH LOCK` * test: check the final state of an indexed file * fix: do not read data when the file status is not 00 * test: move common java code for record lock tests * test: add tests for different records * test: add tests for input mode * test: add tests for the same process * fix: commit at the end of start_ * test: guarantee that OPEN,START,WRITE,REWRITE cannot lock indexed file records * test: fix tests for OPEN,START,WRITE and REWRITE * fix: processes of unlocking records * tests: add tests for unlocking records * tests: add tests of OPEN INPUT * test: add tests for LOCK MODE * test: add tests of -lock-mode-automatic * tests: move tests for indexed files lock to tests/indexed-lock * ci: run tests `indexed-lock` * chore: fix typo * fix: the syntax error of an sql statement in IndexedCursor.java Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent 663eb60 commit f984a89

30 files changed

+5800
-2135
lines changed

.github/workflows/coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
- name: Run other tests
4242
working-directory: tests
4343
run: |
44-
tests=("command-line-options" "data-rep" "i18n_sjis" "jp-compat" "run" "syntax" "cobj-idx" "misc")
44+
tests=("command-line-options" "data-rep" "i18n_sjis" "jp-compat" "run" "syntax" "cobj-idx" "indexed-lock" "misc")
4545
for test in "${tests[@]}"; do
4646
./"$test" || true
4747
done

.github/workflows/pull-request.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ jobs:
5454
- "syntax"
5555
- "cobj-idx"
5656
- "misc"
57+
- "indexed-lock"
5758
os: ["ubuntu:24.04", "almalinux:9", "amazonlinux:2023"]
5859
uses: ./.github/workflows/test-other.yml
5960
with:
@@ -74,6 +75,7 @@ jobs:
7475
- "run"
7576
- "syntax"
7677
- "cobj-idx"
78+
- "indexed-lock"
7779
#- "misc"
7880
os: ["ubuntu:24.04", "almalinux:9", "amazonlinux:2023"]
7981
uses: ./.github/workflows/test-other.yml

.github/workflows/push.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ jobs:
5858
- "run"
5959
- "syntax"
6060
- "cobj-idx"
61+
- "indexed-lock"
6162
- "misc"
6263
os: ["ubuntu:24.04"]
6364
uses: ./.github/workflows/test-other.yml
@@ -79,6 +80,7 @@ jobs:
7980
- "run"
8081
- "syntax"
8182
- "cobj-idx"
83+
- "indexed-lock"
8284
#- "misc"
8385
os: ["ubuntu:24.04"]
8486
uses: ./.github/workflows/test-other.yml

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ tests/jp-compat
5454
tests/cobj-idx
5555
tests/misc
5656
tests/run
57+
tests/indexed-lock
5758
tests/*.log
5859
tests/syntax
5960
tests/cobol85/*/*.class

cobj/cobj.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,14 @@ int cb_flag_main = 0;
145145

146146
int cb_default_byte_specified = 0;
147147
unsigned char cb_default_byte = 0;
148+
149+
int cb_default_select_lock_mode = COB_LOCK_MANUAL;
150+
148151
#define OPTION_ID_DEFAULT_BYTE (1024)
149152
#define OPTION_ID_SINGLE_JAR (1025)
150153
#define OPTION_ID_JAR (1026)
151154
#define OPTION_ID_INFO_JSON (1027)
155+
#define OPTION_ID_LOCK_MODE_AUTOMATIC (1028)
152156

153157
int external_flg = 0;
154158
int errorcount = 0;
@@ -311,6 +315,7 @@ static const struct option long_options[] = {
311315
{"reference_check", no_argument, NULL, 'K'},
312316
{"constant", optional_argument, NULL, '3'},
313317
{"fdefaultbyte", required_argument, NULL, OPTION_ID_DEFAULT_BYTE},
318+
{"lock-mode-automatic", no_argument, NULL, OPTION_ID_LOCK_MODE_AUTOMATIC},
314319
#undef CB_FLAG
315320
#define CB_FLAG(var, name, doc) \
316321
{"f" name, no_argument, &var, 1}, {"fno-" name, no_argument, &var, 0},
@@ -901,6 +906,8 @@ static void cobc_print_usage(void) {
901906
"representing a character"));
902907
puts(_(" * octodecimal 00..0377 "
903908
"representing a character"));
909+
puts(_(" -lock-mode-automatic Set the default lock mode of "
910+
"select clauses to AUTOMATIC"));
904911
puts(_(" -info-json-dir=<dir> Specify the directory path of "
905912
"JSON files that hold information of COBOL programs"));
906913
puts(_(" -java-package(=<package name>) Specify the package name of the "
@@ -1156,6 +1163,10 @@ static int process_command_line(const int argc, char *argv[]) {
11561163
fflush(stderr);
11571164
break;
11581165

1166+
case OPTION_ID_LOCK_MODE_AUTOMATIC:
1167+
cb_default_select_lock_mode = COB_LOCK_AUTOMATIC;
1168+
break;
1169+
11591170
case '3': /* --constant */
11601171
if (optarg) {
11611172
cb_constant_list_add(optarg);

cobj/cobj.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,4 +383,5 @@ extern int cb_verify(const enum cb_support tag, const char *feature);
383383
extern int cb_flag_info_json;
384384
extern char *cb_info_json_dir;
385385

386+
extern int cb_default_select_lock_mode;
386387
#endif /* CB_COBC_H */

cobj/parser.c

Lines changed: 1489 additions & 1449 deletions
Large diffs are not rendered by default.

cobj/parser.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
/* A Bison parser, made by GNU Bison 3.8.2. */
1+
/* A Bison parser, made by GNU Bison 3.7.4. */
22

33
/* Bison interface for Yacc-like parsers in C
44
5-
Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
5+
Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation,
66
Inc.
77
88
This program is free software: you can redistribute it and/or modify
@@ -16,7 +16,7 @@
1616
GNU General Public License for more details.
1717
1818
You should have received a copy of the GNU General Public License
19-
along with this program. If not, see <https://www.gnu.org/licenses/>. */
19+
along with this program. If not, see <http://www.gnu.org/licenses/>. */
2020

2121
/* As a special exception, you may create a larger work that contains
2222
part or all of the Bison parser skeleton and distribute that work
@@ -515,8 +515,6 @@ typedef int YYSTYPE;
515515

516516
extern YYSTYPE yylval;
517517

518-
519518
int yyparse (void);
520519

521-
522520
#endif /* !YY_YY_PARSER_H_INCLUDED */

cobj/parser.y

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5382,9 +5382,7 @@ read_statement:
53825382
CB_FILE(cb_ref ($3))->organization != COB_ORG_INDEXED)) {
53835383
current_statement->handler_id = COB_EC_I_O_PERMANENT_ERROR;
53845384
}
5385-
if ($7 && (CB_FILE(cb_ref ($3))->lock_mode & COB_LOCK_AUTOMATIC)) {
5386-
cb_error (_("LOCK clause invalid with file LOCK AUTOMATIC"));
5387-
} else if ($8 &&
5385+
if ($8 &&
53885386
(CB_FILE(cb_ref ($3))->organization != COB_ORG_RELATIVE &&
53895387
CB_FILE(cb_ref ($3))->organization != COB_ORG_INDEXED)) {
53905388
cb_error (_("KEY clause invalid with this file type"));

cobj/tree.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,6 +1725,7 @@ struct cb_file *build_file(cb_tree name) {
17251725
p->access_mode = COB_ACCESS_SEQUENTIAL;
17261726
p->handler = CB_LABEL(cb_standard_error_handler);
17271727
p->handler_prog = current_program;
1728+
p->lock_mode = cb_default_select_lock_mode;
17281729
if (external_flg == 1) {
17291730
p->external_assign = 1;
17301731
}

0 commit comments

Comments
 (0)