7323-JMX.patch
new/src/com/goldencode/p2j/jmx/FwdJMX.java 2023-07-04 11:18:24 +0000 | ||
---|---|---|
27 | 27 |
** OM 20230112 Added finer-granulation instrumentation for processing of dynamic queries. |
28 | 28 |
** 004 RAA 20230302 Removed OrmRedo and OrmNoUndoTrace. |
29 | 29 |
** 005 GBB 20230512 Logging methods replaced by CentralLogger/ConversionStatus. |
30 |
** 006 RAA 20230704 Added InsertUpdateValidateTotal and InsertUpdateValidateSuccess. |
|
30 | 31 |
*/ |
31 | 32 | |
32 | 33 |
/* |
... | ... | |
544 | 545 |
public static enum Counter |
545 | 546 |
implements OptionalCounter |
546 | 547 |
{ |
548 |
/** How many Insert/Update statements that contain the VALIDATE keyword are there */ |
|
549 |
InsertUpdateValidateTotal, |
|
550 |
/** |
|
551 |
* How many Insert/Update statements that contain the VALIDATE keyword have been executed successfully. |
|
552 |
*/ |
|
553 |
InsertUpdateValidateSuccess, |
|
554 |
/** How many inserts with VALIDATE were cured after failing the first time. */ |
|
555 |
InsertValidateCured, |
|
556 |
|
|
547 | 557 |
/** Incomning network traffic */ |
548 | 558 |
NetworkReads, |
549 | 559 |
/** Outgoing network traffic */ |
new/src/com/goldencode/p2j/persist/orm/Persister.java 2023-07-04 11:18:24 +0000 | ||
---|---|---|
27 | 27 |
** more straight-forward. |
28 | 28 |
** RAA 20230623 Instead of appending "validate" to the insert SQL, insertValidateSql is now used. |
29 | 29 |
** RAA 20230704 Changed name of validateMode to allowDBUniqueCheck. |
30 |
** RAA 20230704 Added JMXs for counting how many Inserts/Updates with VALIDATE are executed. |
|
30 | 31 |
*/ |
31 | 32 | |
32 | 33 |
/* |
... | ... | |
88 | 89 |
import java.util.*; |
89 | 90 |
import java.util.logging.*; |
90 | 91 |
import com.goldencode.cache.*; |
92 |
import com.goldencode.p2j.jmx.*; |
|
91 | 93 |
import com.goldencode.p2j.persist.*; |
92 | 94 |
import com.goldencode.p2j.persist.orm.types.*; |
93 | 95 |
import com.goldencode.p2j.util.logging.*; |
... | ... | |
112 | 114 |
/** Cache of FQL strings, with or without max results and start offsets, to queries. */ |
113 | 115 |
private static ExpiryCache<UpdateInfo, UpdateInfo> updateCache = new LRUCache<>(4096); |
114 | 116 |
|
117 |
/** Counter for how many Inserts/Updates with VALIDATE are executed. */ |
|
118 |
private static final SimpleCounter INSERT_UPDATE_VALIDATE_TOTAL = |
|
119 |
SimpleCounter.getInstance(FwdJMX.Counter.InsertUpdateValidateTotal); |
|
120 |
|
|
121 |
/** Counter for how many Inserts/Updates with VALIDATE are successfully executed. */ |
|
122 |
private static final SimpleCounter INSERT_UPDATE_VALIDATE_SUCCESS = |
|
123 |
SimpleCounter.getInstance(FwdJMX.Counter.InsertUpdateValidateSuccess); |
|
124 |
|
|
115 | 125 |
/** |
116 | 126 |
* Constructor. |
117 | 127 |
* |
... | ... | |
786 | 796 |
LOG.log(Level.FINE, "FWD ORM: " + ps); |
787 | 797 |
} |
788 | 798 |
|
799 |
if (allowDBUniqueCheck) |
|
800 |
{ |
|
801 |
INSERT_UPDATE_VALIDATE_TOTAL.update(1); |
|
802 |
} |
|
803 |
|
|
789 | 804 |
int[] result = new int[1]; |
790 | 805 |
SQLStatementLogger.getLogger().log(session.getDatabase(), ps, |
791 | 806 |
() -> result[0] = ps.executeUpdate()); |
792 | 807 |
updateCount += result[0]; |
793 | 808 |
|
809 |
if (allowDBUniqueCheck) |
|
810 |
{ |
|
811 |
INSERT_UPDATE_VALIDATE_SUCCESS.update(1); |
|
812 |
} |
|
813 |
|
|
794 | 814 |
if (updateCount == 0 && LOG.isLoggable(Level.WARNING)) |
795 | 815 |
{ |
796 | 816 |
LOG.log(Level.WARNING, |
... | ... | |
963 | 983 |
} |
964 | 984 |
else |
965 | 985 |
{ |
986 |
boolean countValidateJMX = INSERT_UPDATE_VALIDATE_TOTAL.isEnabled() && |
|
987 |
INSERT_UPDATE_VALIDATE_SUCCESS.isEnabled() && |
|
988 |
ps.toString().contains("validate"); |
|
989 |
|
|
990 |
if (countValidateJMX) |
|
991 |
{ |
|
992 |
INSERT_UPDATE_VALIDATE_TOTAL.update(1); |
|
993 |
} |
|
994 |
|
|
966 | 995 |
// non-batch insert is executed inline here |
967 | 996 |
SQLStatementLogger.getLogger().log(session.getDatabase(), ps, () -> ps.execute()); |
968 | 997 |
count++; |
998 |
|
|
999 |
if (countValidateJMX) |
|
1000 |
{ |
|
1001 |
INSERT_UPDATE_VALIDATE_SUCCESS.update(1); |
|
1002 |
} |
|
969 | 1003 |
} |
970 | 1004 |
} |
971 | 1005 |
|
... | ... | |
973 | 1007 |
// executes the batches (since the scope of the batch is larger than a single DMO) |
974 | 1008 |
if (batch && !bulk) |
975 | 1009 |
{ |
1010 |
boolean countValidateJMX = INSERT_UPDATE_VALIDATE_TOTAL.isEnabled() && |
|
1011 |
INSERT_UPDATE_VALIDATE_SUCCESS.isEnabled() && |
|
1012 |
ps.toString().contains("validate"); |
|
1013 |
|
|
1014 |
if (countValidateJMX) |
|
1015 |
{ |
|
1016 |
INSERT_UPDATE_VALIDATE_TOTAL.update(1); |
|
1017 |
} |
|
1018 |
|
|
976 | 1019 |
int[] result = new int[1]; |
977 | 1020 |
SQLStatementLogger.getLogger().log(session.getDatabase(), ps, |
978 | 1021 |
() -> result[0] = executeBatch(ps)); |
979 | 1022 |
count += result[0]; |
1023 |
|
|
1024 |
if (countValidateJMX) |
|
1025 |
{ |
|
1026 |
INSERT_UPDATE_VALIDATE_SUCCESS.update(1); |
|
1027 |
} |
|
980 | 1028 |
} |
981 | 1029 |
|
982 | 1030 |
// [i] was only advanced through first element in the extent series; need to push |
new/src/com/goldencode/p2j/persist/orm/Validation.java 2023-07-04 11:19:46 +0000 | ||
---|---|---|
39 | 39 |
** RAA 20230619 Split flush function into two for more straight-forward use when dealing with VALIDATE. |
40 | 40 |
** RAA 20230704 Changed name of validateMode to allowDBUniqueCheck. |
41 | 41 |
** RAA 20230704 In case a flush with VALIDATE fails, but it gets cured, a second flush is now attempted. |
42 |
** RAA 20230704 Added JMXs for counting how many Inserts/Updates with VALIDATE are cured. |
|
42 | 43 |
*/ |
43 | 44 | |
44 | 45 |
/* |
... | ... | |
100 | 101 |
import java.sql.*; |
101 | 102 |
import java.util.*; |
102 | 103 |
import com.goldencode.p2j.directory.*; |
104 |
import com.goldencode.p2j.jmx.*; |
|
103 | 105 |
import com.goldencode.p2j.persist.*; |
104 | 106 |
import com.goldencode.p2j.persist.dialect.*; |
105 | 107 |
import com.goldencode.p2j.persist.orm.types.*; |
... | ... | |
160 | 162 |
/** Flag indicating the record was flushed to the database (either newly inserted or updated) */ |
161 | 163 |
private boolean flushed = false; |
162 | 164 |
|
165 |
/** Counter for how many Inserts/Updates with VALIDATE are executed. */ |
|
166 |
private static final SimpleCounter INSERT_VALIDATE_CURED = |
|
167 |
SimpleCounter.getInstance(FwdJMX.Counter.InsertValidateCured); |
|
168 |
|
|
163 | 169 |
/** |
164 | 170 |
* The maximum permitted size for all combined fields of an index. By default this |
165 | 171 |
* is equal to Progress version 10.x limit of 1971 bytes. |
... | ... | |
447 | 453 |
if ((multiplex != null || !flush) && !allowDBUniqueCheck) |
448 | 454 |
{ |
449 | 455 |
// validate by executing unique index queries |
450 |
validateUniqueByQuery(check); |
|
456 |
validateUniqueByQuery(check, false);
|
|
451 | 457 |
} |
452 | 458 |
|
453 | 459 |
if (willFlush) |
... | ... | |
709 | 715 |
{ |
710 | 716 |
// if the right index is found, this method will not return normally, instead it will |
711 | 717 |
// throw a specific exception |
712 |
validateUniqueByQuery(null); |
|
718 |
validateUniqueByQuery(null, allowDBUniqueCheck);
|
|
713 | 719 |
if (allowDBUniqueCheck) |
714 | 720 |
{ |
715 | 721 |
// We were not able to execute the query with VALIDATE, but a "cure" occurred, |
... | ... | |
1113 | 1119 |
* @param check |
1114 | 1120 |
* A bit set whose set bits represent the positions of the unique indices in the DMO's array |
1115 | 1121 |
* of unique indices to be checked. If {@code null}, check all the unique indices. |
1122 |
* @param allowDBUniqueCheck |
|
1123 |
* Flag that marks whether the database is capable of doing the index validation itself, meaning |
|
1124 |
* that server-side validation can be skipped. |
|
1116 | 1125 |
* |
1117 | 1126 |
* @throws ValidationException |
1118 | 1127 |
* when the method detects a collision of current DMO with another record stored in the database. |
1119 | 1128 |
* @throws PersistenceException |
1120 | 1129 |
* if an error occurred while accessing the database. |
1121 | 1130 |
*/ |
1122 |
private void validateUniqueByQuery(BitSet check) |
|
1131 |
private void validateUniqueByQuery(BitSet check, boolean allowDBUniqueCheck)
|
|
1123 | 1132 |
throws PersistenceException, |
1124 | 1133 |
ValidationException |
1125 | 1134 |
{ |
... | ... | |
1188 | 1197 |
{ |
1189 | 1198 |
throw new ValidationException(getFailUniqueIndexMessage(uIndex, bufferName, dmo), 132); |
1190 | 1199 |
} |
1200 |
else if (allowDBUniqueCheck) |
|
1201 |
{ |
|
1202 |
INSERT_VALIDATE_CURED.update(1); |
|
1203 |
} |
|
1191 | 1204 |
|
1192 | 1205 |
// if we exit the loop normally, all violations are cured by in-memory changes (which may yet |
1193 | 1206 |
// have to be validated and flushed themselves) |