Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2020-06-10 03:05:10 +0000
committerEike Stepper2020-06-10 03:05:10 +0000
commit4d81d551908af31b5956120c5b47217520d52698 (patch)
treeaf776e0af7b8dd896a113d94901ec71d3b91d58f
parent4cfed2e8b5dfb978766c45b390b283db74923cd8 (diff)
downloadcdo-4d81d551908af31b5956120c5b47217520d52698.tar.gz
cdo-4d81d551908af31b5956120c5b47217520d52698.tar.xz
cdo-4d81d551908af31b5956120c5b47217520d52698.zip
[Releng] Add schema access tracking option
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBDatabase.java134
1 files changed, 61 insertions, 73 deletions
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBDatabase.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBDatabase.java
index 7645fff2b5..ab355e2112 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBDatabase.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBDatabase.java
@@ -46,7 +46,7 @@ public final class DBDatabase extends SetContainer<IDBConnection> implements IDB
private static final boolean DEBUG_SCHEMA_ACCESS = OMPlatform.INSTANCE.isProperty("org.eclipse.net4j.internal.db.DBDatabase.DEBUG_SCHEMA_ACCESS");
- private static final boolean TRACK_SCHEMA_ACCESS = true || OMPlatform.INSTANCE.isProperty("org.eclipse.net4j.internal.db.DBDatabase.TRACK_SCHEMA_ACCESS");
+ private static final boolean TRACK_SCHEMA_ACCESS = OMPlatform.INSTANCE.isProperty("org.eclipse.net4j.internal.db.DBDatabase.TRACK_SCHEMA_ACCESS");
private DBAdapter adapter;
@@ -242,106 +242,94 @@ public final class DBDatabase extends SetContainer<IDBConnection> implements IDB
}
}
- boolean success = false;
Object token = null;
SchemaAccess schemaAccess = null;
- try
+ synchronized (schemaAccessQueue)
{
- synchronized (schemaAccessQueue)
+ if (write)
{
- if (write)
- {
- schemaAccess = createWriteSchemaAccess();
- token = schemaAccess;
- schemaAccessQueue.addLast(schemaAccess);
- ++waitingSchemaWriters;
- }
- else
+ schemaAccess = createWriteSchemaAccess();
+ token = schemaAccess;
+ schemaAccessQueue.addLast(schemaAccess);
+ ++waitingSchemaWriters;
+ }
+ else
+ {
+ if (waitingSchemaWriters == 0 && !schemaAccessQueue.isEmpty())
{
- if (waitingSchemaWriters == 0 && !schemaAccessQueue.isEmpty())
+ schemaAccess = schemaAccessQueue.getFirst();
+ if (schemaAccess instanceof ReadSchemaAccess)
{
- schemaAccess = schemaAccessQueue.getFirst();
- if (schemaAccess instanceof ReadSchemaAccess)
- {
- ReadSchemaAccess readSchemaAccess = (ReadSchemaAccess)schemaAccess;
- token = readSchemaAccess.addReader();
- }
- else
- {
- schemaAccess = null;
- }
+ ReadSchemaAccess readSchemaAccess = (ReadSchemaAccess)schemaAccess;
+ token = readSchemaAccess.addReader();
}
-
- if (schemaAccess == null)
+ else
{
- ReadSchemaAccess readSchemaAccess = createReadSchemaAccess();
- token = readSchemaAccess.addReader();
-
- schemaAccess = readSchemaAccess;
- schemaAccessQueue.addLast(schemaAccess);
+ schemaAccess = null;
}
}
+
+ if (schemaAccess == null)
+ {
+ ReadSchemaAccess readSchemaAccess = createReadSchemaAccess();
+ token = readSchemaAccess.addReader();
+
+ schemaAccess = readSchemaAccess;
+ schemaAccessQueue.addLast(schemaAccess);
+ }
}
+ }
- long end = System.currentTimeMillis() + TIMEOUT_SCHEMA_ACCESS;
+ long end = System.currentTimeMillis() + TIMEOUT_SCHEMA_ACCESS;
- for (;;)
+ for (;;)
+ {
+ synchronized (schemaAccessQueue)
{
- synchronized (schemaAccessQueue)
+ SchemaAccess activeSchemaAccess = schemaAccessQueue.getFirst();
+ if (activeSchemaAccess == schemaAccess)
{
- SchemaAccess activeSchemaAccess = schemaAccessQueue.getFirst();
- if (activeSchemaAccess == schemaAccess)
+ if (write)
{
- if (write)
- {
- --waitingSchemaWriters;
- }
-
- success = true;
- return token;
+ --waitingSchemaWriters;
}
- try
- {
- schemaAccessQueue.wait(1000L);
- }
- catch (InterruptedException ex)
- {
- Thread.currentThread().interrupt();
- throw WrappedException.wrap(ex);
- }
+ return token;
+ }
- if (System.currentTimeMillis() >= end)
- {
- StringBuilder builder = new StringBuilder("Schema " + schema.getName() + " could not be locked for " + (write ? "write" : "read")
- + " access within " + TIMEOUT_SCHEMA_ACCESS + " milliseconds. Schema access queue:" + StringUtil.NL);
- int i = 0;
+ try
+ {
+ schemaAccessQueue.wait(1000L);
+ }
+ catch (InterruptedException ex)
+ {
+ Thread.currentThread().interrupt();
+ throw WrappedException.wrap(ex);
+ }
+
+ if (System.currentTimeMillis() >= end)
+ {
+ StringBuilder builder = new StringBuilder("Schema " + schema.getName() + " could not be locked for " + (write ? "write" : "read") + " access within "
+ + TIMEOUT_SCHEMA_ACCESS + " milliseconds. Schema access queue:" + StringUtil.NL);
+ int i = 0;
- for (SchemaAccess blockingAccess : schemaAccessQueue)
+ for (SchemaAccess blockingAccess : schemaAccessQueue)
+ {
+ if (blockingAccess == schemaAccess)
{
- if (blockingAccess == schemaAccess)
- {
- builder.append("--> ");
- }
-
- builder.append(i++);
- builder.append(": ");
- builder.append(blockingAccess);
+ builder.append("--> ");
}
- throw new TimeoutRuntimeException(builder.toString());
+ builder.append(i++);
+ builder.append(": ");
+ builder.append(blockingAccess);
}
+
+ throw new TimeoutRuntimeException(builder.toString());
}
}
}
- finally
- {
- if (!success)
- {
- schemaAccessQueue.remove(schemaAccess);
- }
- }
}
public void endSchemaAccess(Object token)

Back to the top