Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OLAT CI-CD Testing Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lars Oliver Dam
OLAT CI-CD Testing Project
Commits
ef3f74b4
Commit
ef3f74b4
authored
4 years ago
by
srosse
Browse files
Options
Downloads
Patches
Plain Diff
no-jira: paged upgrade 15.0.3 for memory efficiency
parent
d93d9f99
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/org/olat/upgrade/OLATUpgrade_15_0_3.java
+51
-21
51 additions, 21 deletions
src/main/java/org/olat/upgrade/OLATUpgrade_15_0_3.java
with
51 additions
and
21 deletions
src/main/java/org/olat/upgrade/OLATUpgrade_15_0_3.java
+
51
−
21
View file @
ef3f74b4
...
@@ -49,9 +49,14 @@ public class OLATUpgrade_15_0_3 extends OLATUpgrade {
...
@@ -49,9 +49,14 @@ public class OLATUpgrade_15_0_3 extends OLATUpgrade {
private
static
final
Logger
log
=
Tracing
.
createLoggerFor
(
OLATUpgrade_15_0_3
.
class
);
private
static
final
Logger
log
=
Tracing
.
createLoggerFor
(
OLATUpgrade_15_0_3
.
class
);
private
static
final
int
BATCH_SIZE
=
50000
;
private
static
final
String
VERSION
=
"OLAT_15.0.3"
;
private
static
final
String
VERSION
=
"OLAT_15.0.3"
;
private
static
final
String
ASSESSMENT_LAST_ATTEMPTS
=
"ASSESSMENT LAST ATTEMPTS"
;
private
static
final
String
ASSESSMENT_LAST_ATTEMPTS
=
"ASSESSMENT LAST ATTEMPTS"
;
private
final
AtomicInteger
migrationLogCounter
=
new
AtomicInteger
(
0
);
private
final
AtomicInteger
migrationEntryCounter
=
new
AtomicInteger
(
0
);
@Autowired
@Autowired
private
DB
dbInstance
;
private
DB
dbInstance
;
@Autowired
@Autowired
...
@@ -97,10 +102,35 @@ public class OLATUpgrade_15_0_3 extends OLATUpgrade {
...
@@ -97,10 +102,35 @@ public class OLATUpgrade_15_0_3 extends OLATUpgrade {
boolean
allOk
=
true
;
boolean
allOk
=
true
;
if
(!
uhd
.
getBooleanDataValue
(
ASSESSMENT_LAST_ATTEMPTS
))
{
if
(!
uhd
.
getBooleanDataValue
(
ASSESSMENT_LAST_ATTEMPTS
))
{
try
{
try
{
List
<
LoggingObject
>
loggedLaunches
=
getLoggedLastAttempts
();
int
counter
=
0
;
migrateLoggedAttempts
(
loggedLaunches
);
List
<
LoggingObject
>
loggedLaunches
;
List
<
AssessmentEntry
>
entries
=
getEmptyLastAttempts
();
do
{
migrateEmptyLastAttempts
(
entries
);
loggedLaunches
=
getLoggedLastAttempts
(
counter
,
BATCH_SIZE
);
migrateLoggedAttempts
(
loggedLaunches
);
counter
+=
loggedLaunches
.
size
();
log
.
info
(
Tracing
.
M_AUDIT
,
"Log launch processed: {}, total processed ({})"
,
loggedLaunches
.
size
(),
counter
);
dbInstance
.
commitAndCloseSession
();
}
while
(
loggedLaunches
.
size
()
==
BATCH_SIZE
);
log
.
info
(
Tracing
.
M_AUDIT
,
"Log launch processing successful, total processed: {}"
,
migrationLogCounter
);
}
catch
(
Exception
e
)
{
log
.
error
(
""
,
e
);
allOk
=
false
;
}
try
{
int
counter
=
0
;
List
<
AssessmentEntry
>
entries
;
do
{
entries
=
getEmptyLastAttempts
(
counter
,
BATCH_SIZE
);
migrateEmptyLastAttempts
(
entries
);
counter
+=
entries
.
size
();
log
.
info
(
Tracing
.
M_AUDIT
,
"Empty last attempts processed: {}, total processed ({})"
,
entries
.
size
(),
counter
);
dbInstance
.
commitAndCloseSession
();
}
while
(
entries
.
size
()
==
BATCH_SIZE
);
log
.
info
(
"Assessment entry last attemps processing successful, total processed: {}"
,
migrationEntryCounter
);
log
.
info
(
"Assessment last modified migrated."
);
log
.
info
(
"Assessment last modified migrated."
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
""
,
e
);
log
.
error
(
""
,
e
);
...
@@ -112,7 +142,7 @@ public class OLATUpgrade_15_0_3 extends OLATUpgrade {
...
@@ -112,7 +142,7 @@ public class OLATUpgrade_15_0_3 extends OLATUpgrade {
return
allOk
;
return
allOk
;
}
}
private
List
<
LoggingObject
>
getLoggedLastAttempts
()
{
private
List
<
LoggingObject
>
getLoggedLastAttempts
(
int
firstResult
,
int
maxResults
)
{
QueryBuilder
sb
=
new
QueryBuilder
();
QueryBuilder
sb
=
new
QueryBuilder
();
sb
.
append
(
"select log"
);
sb
.
append
(
"select log"
);
sb
.
append
(
" from loggingobject log"
);
sb
.
append
(
" from loggingobject log"
);
...
@@ -121,29 +151,29 @@ public class OLATUpgrade_15_0_3 extends OLATUpgrade {
...
@@ -121,29 +151,29 @@ public class OLATUpgrade_15_0_3 extends OLATUpgrade {
return
dbInstance
.
getCurrentEntityManager
()
return
dbInstance
.
getCurrentEntityManager
()
.
createQuery
(
sb
.
toString
(),
LoggingObject
.
class
)
.
createQuery
(
sb
.
toString
(),
LoggingObject
.
class
)
.
setFirstResult
(
firstResult
)
.
setMaxResults
(
maxResults
)
.
getResultList
();
.
getResultList
();
}
}
private
void
migrateLoggedAttempts
(
List
<
LoggingObject
>
loggedAttempts
)
{
private
void
migrateLoggedAttempts
(
List
<
LoggingObject
>
loggedAttempts
)
{
log
.
info
(
"Migraton of {} assessment last attemps (log table) started."
,
loggedAttempts
.
size
());
Map
<
Long
,
Identity
>
identityCache
=
new
HashMap
<>();
Map
<
Long
,
Identity
>
identityCache
=
new
HashMap
<>();
Map
<
Long
,
RepositoryEntry
>
entryCache
=
new
HashMap
<>();
Map
<
Long
,
RepositoryEntry
>
entryCache
=
new
HashMap
<>();
AtomicInteger
migrationCounter
=
new
AtomicInteger
(
0
);
for
(
LoggingObject
loggingObject
:
loggedAttempts
)
{
for
(
LoggingObject
loggingObject
:
loggedAttempts
)
{
try
{
try
{
migrateLastAttempt
(
loggingObject
,
identityCache
,
entryCache
);
migrateLastAttempt
(
loggingObject
,
identityCache
,
entryCache
);
migrationCounter
.
incrementAndGet
();
migration
Log
Counter
.
incrementAndGet
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
warn
(
"Assessment last attempt (log table) not migrated. Id={}"
,
loggingObject
.
getKey
());
log
.
warn
(
"Assessment last attempt (log table) not migrated. Id={}"
,
loggingObject
.
getKey
());
}
}
if
(
migrationCounter
.
get
()
%
25
==
0
)
{
if
(
migration
Log
Counter
.
get
()
%
25
==
0
)
{
dbInstance
.
commitAndCloseSession
();
dbInstance
.
commitAndCloseSession
();
}
else
{
}
else
{
dbInstance
.
commit
();
dbInstance
.
commit
();
}
}
if
(
migrationCounter
.
get
()
%
100
==
0
)
{
if
(
migration
Log
Counter
.
get
()
%
100
==
0
)
{
log
.
info
(
"Assessment: num. of last attempts (log table): {}"
,
migrationCounter
);
log
.
info
(
"Assessment: num. of last attempts (log table): {}"
,
migration
Log
Counter
);
}
}
}
}
}
}
...
@@ -196,20 +226,20 @@ public class OLATUpgrade_15_0_3 extends OLATUpgrade {
...
@@ -196,20 +226,20 @@ public class OLATUpgrade_15_0_3 extends OLATUpgrade {
}
}
}
}
private
List
<
AssessmentEntry
>
getEmptyLastAttempts
()
{
private
List
<
AssessmentEntry
>
getEmptyLastAttempts
(
int
firstResult
,
int
maxResults
)
{
StringBuilder
sb
=
new
StringBuilder
();
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"select data from assessmententry data"
);
sb
.
append
(
"select data from assessmententry data"
);
sb
.
append
(
" where data.attempts > 0 and lastAttempt is null"
);
sb
.
append
(
" where data.attempts > 0 and lastAttempt is null"
);
sb
.
append
(
" order by data.key asc"
);
return
dbInstance
.
getCurrentEntityManager
()
return
dbInstance
.
getCurrentEntityManager
()
.
createQuery
(
sb
.
toString
(),
AssessmentEntry
.
class
)
.
createQuery
(
sb
.
toString
(),
AssessmentEntry
.
class
)
.
setFirstResult
(
firstResult
)
.
setMaxResults
(
maxResults
)
.
getResultList
();
.
getResultList
();
}
}
private
void
migrateEmptyLastAttempts
(
List
<
AssessmentEntry
>
entries
)
{
private
void
migrateEmptyLastAttempts
(
List
<
AssessmentEntry
>
entries
)
{
log
.
info
(
"Migraton of {} assessment last attemps (empty) started."
,
entries
.
size
());
AtomicInteger
migrationCounter
=
new
AtomicInteger
(
0
);
for
(
AssessmentEntry
assessmentEntry:
entries
)
{
for
(
AssessmentEntry
assessmentEntry:
entries
)
{
try
{
try
{
if
(
assessmentEntry
.
getAttempts
()
!=
null
&&
assessmentEntry
.
getAttempts
().
intValue
()
>
0
&&
assessmentEntry
.
getLastAttempt
()
==
null
)
{
if
(
assessmentEntry
.
getAttempts
()
!=
null
&&
assessmentEntry
.
getAttempts
().
intValue
()
>
0
&&
assessmentEntry
.
getLastAttempt
()
==
null
)
{
...
@@ -219,17 +249,17 @@ public class OLATUpgrade_15_0_3 extends OLATUpgrade {
...
@@ -219,17 +249,17 @@ public class OLATUpgrade_15_0_3 extends OLATUpgrade {
assessmentEntry
.
setLastAttempt
(
lastAttemps
);
assessmentEntry
.
setLastAttempt
(
lastAttemps
);
assessmentService
.
updateAssessmentEntry
(
assessmentEntry
);
assessmentService
.
updateAssessmentEntry
(
assessmentEntry
);
}
}
migrationCounter
.
incrementAndGet
();
migration
Entry
Counter
.
incrementAndGet
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
warn
(
"Assessment last attempt (empty) not migrated. Id={}"
,
assessmentEntry
.
getKey
());
log
.
warn
(
"Assessment last attempt (empty) not migrated. Id={}"
,
assessmentEntry
.
getKey
());
}
}
if
(
migrationCounter
.
get
()
%
25
==
0
)
{
if
(
migration
Entry
Counter
.
get
()
%
25
==
0
)
{
dbInstance
.
commitAndCloseSession
();
dbInstance
.
commitAndCloseSession
();
}
else
{
}
else
{
dbInstance
.
commit
();
dbInstance
.
commit
();
}
}
if
(
migrationCounter
.
get
()
%
100
==
0
)
{
if
(
migration
Entry
Counter
.
get
()
%
100
==
0
)
{
log
.
info
(
"Assessment: num. of last attempts (empty): {}"
,
migrationCounter
);
log
.
info
(
"Assessment: num. of last attempts (empty): {}"
,
migration
Entry
Counter
);
}
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment