Got rid of a lot of no longer needed work in Lookup.add(). Minimized

the number of explicit session.flush()s. Fixed several places that
were throwing uninformative exceptions.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3227 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-06-23 14:57:26 +00:00
parent ff4fe08d04
commit b580c28494
11 changed files with 67 additions and 186 deletions

View File

@@ -17,7 +17,7 @@
<property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<!-- <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property> -->
<property name="show_sql">false</property>
<property name="order_updates">false</property>
<property name="order_updates">true</property>
<property name="connection.isolation">2</property>
<!--

View File

@@ -1813,13 +1813,13 @@ public class AVMServiceTest extends AVMServiceTestBase
{
ArrayList<Long> times = new ArrayList<Long>();
BulkLoader loader = new BulkLoader(fService);
loader.recursiveLoad("source/java/org/alfresco/repo", "main:/");
loader.recursiveLoad("source/java/org/alfresco/repo/avm", "main:/");
times.add(System.currentTimeMillis());
fService.createSnapshot("main");
loader.recursiveLoad("source/java/org/alfresco/service", "main:/");
loader.recursiveLoad("source/java/org/alfresco/repo/action", "main:/");
times.add(System.currentTimeMillis());
fService.createSnapshot("main");
loader.recursiveLoad("source/java/org/alfresco/filesys", "main:/");
loader.recursiveLoad("source/java/org/alfresco/repo/audit", "main:/");
times.add(System.currentTimeMillis());
fService.createSnapshot("main");
assertEquals(1, fService.getRepositoryVersions("main", null, new Date(times.get(0))).size());

View File

@@ -36,7 +36,7 @@ public class AVMStressTest extends AVMServiceTestBase
try
{
int nCopies = 1;
int nThreads = 16;
int nThreads = 8;
BulkLoader loader = new BulkLoader(fService);
long start = System.currentTimeMillis();
for (int i = 0; i < nCopies; i++)

View File

@@ -532,7 +532,14 @@ class AVMTester implements Runnable
private void snapshot()
{
System.out.println("snapshot");
fService.createSnapshot("main");
try
{
fService.createSnapshot("main");
}
catch (AVMExistsException aee)
{
// Do nothing. It's OK.
}
}
public boolean getError()

View File

@@ -89,7 +89,6 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
fPrimaryIndirection = other.getPrimaryIndirection();
fLayerID = -1;
sess.save(this);
sess.flush();
for (ChildEntry child : other.getChildren())
{
ChildEntryImpl newChild = new ChildEntryImpl(child.getName(),
@@ -126,7 +125,6 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
sess.save(this);
if (copyContents)
{
sess.flush();
for (ChildEntry child : other.getChildren())
{
ChildEntryImpl newChild = new ChildEntryImpl(child.getName(),

View File

@@ -48,6 +48,11 @@ class Lookup
* Used while building a Lookup.
*/
private boolean fLayeredYet;
/**
* Whether we are directly contained at this point.
*/
private boolean fDirectlyContained;
/**
* The first LayeredDirectoryNode in the path.
@@ -90,6 +95,7 @@ class Lookup
fTopLayerIndex = -1;
fLowestLayerIndex = -1;
fNeedsCopying = false;
fDirectlyContained = true;
}
/**
@@ -104,22 +110,41 @@ class Lookup
LookupComponent comp = new LookupComponent();
comp.setName(name);
comp.setNode(node);
if (!write)
{
if (node.getType() == AVMNodeType.LAYERED_DIRECTORY)
{
LayeredDirectoryNode oNode = (LayeredDirectoryNode)node;
if (oNode.getPrimaryIndirection())
{
comp.setIndirection(oNode.getUnderlying());
}
else
{
comp.setIndirection(computeIndirection(name));
}
}
fComponents.add(comp);
fPosition++;
return;
}
// SuperRepository.GetInstance().getSession().lock(node, LockMode.READ);
if (fPosition >= 0 && fDirectlyContained &&
fComponents.get(fPosition).getNode().getType() == AVMNodeType.LAYERED_DIRECTORY)
{
fDirectlyContained = ((DirectoryNode)fComponents.get(fPosition).getNode()).directlyContains(node);
}
if (!node.getIsNew())
{
fNeedsCopying = true;
}
else
{
// TODO The isDirectlyContained should be eliminated in favor of
// a cumulative state.
if (fPosition >= 0 && (!((DirectoryNode)fComponents.get(fPosition).getNode()).directlyContains(node) ||
!isDirectlyContained()))
if (fPosition >= 0 && !fDirectlyContained)
{
fNeedsCopying = true;
}
}
comp.setNeedsCopy(fNeedsCopying);
// Record various things if this is layered.
if (node.getType() == AVMNodeType.LAYERED_DIRECTORY)
{
@@ -144,24 +169,23 @@ class Lookup
}
// In a write context a plain directory contained in a layer will
// be copied so we will need to compute an indirection path.
else if (fLayeredYet && write)
else if (fLayeredYet)
{
comp.setIndirection(computeIndirection(name));
}
comp.setLowestLayerIndex(fLowestLayerIndex);
comp.setLayered(fLayeredYet);
fComponents.add(comp);
fPosition++;
// If we are in a write context do copy on write.
if (write && fNeedsCopying)
if (fNeedsCopying)
{
node = node.copy(this);
node.setVersionID(fRepository.getNextVersionID());
fComponents.get(fPosition).setNode(node);
if (fPosition == 0)
{
// Inform the repository of a new root.
fRepository.setNewRoot((DirectoryNode)node);
SuperRepository.GetInstance().getSession().flush();
// SuperRepository.GetInstance().getSession().flush();
return;
}
// Not the root. Check if we are the top layer and insert this into it's parent.
@@ -170,7 +194,6 @@ class Lookup
fTopLayer = (LayeredDirectoryNode)node;
}
((DirectoryNode)fComponents.get(fPosition - 1).getNode()).putChild(name, node);
SuperRepository.GetInstance().getSession().flush();
}
}
@@ -201,88 +224,22 @@ class Lookup
return fComponents.get(fPosition).getNode();
}
/**
* Set the current node to one higher in the lookup. This is used
* repeatedly during copy on write.
*/
public void upCurrentNode()
{
fPosition--;
}
/**
* Is the current path layered.
* @return Whether the current position in the path is layered.
*/
public boolean isLayered()
{
assert fPosition >= 0;
return fComponents.get(fPosition).isLayered();
return fLayeredYet;
}
/**
* Determine if a node is directly contained.
*/
private boolean isDirectlyContained()
{
if (!isLayered())
{
return true;
}
int pos = fPosition;
while (pos > 1)
{
DirectoryNode dir = (DirectoryNode)fComponents.get(pos - 1).getNode();
if (!dir.directlyContains(fComponents.get(pos).getNode()))
{
return false;
}
pos--;
}
return true;
}
/**
* Determine if a node is directly in this layer.
* @return Whether this node is directly in this layer.
*/
public boolean isInThisLayer()
{
if (!isLayered())
{
return false;
}
int pos = fPosition;
// Special case of the top layer.
if (fComponents.get(pos).getNode() == fTopLayer)
{
return true;
}
// Walk up the containment chain and determine if each parent-child
// relationship is one of direct containment.
while (pos > 1)
{
DirectoryNode dir = (DirectoryNode)fComponents.get(pos - 1).getNode();
if (!dir.directlyContains(fComponents.get(pos).getNode()))
{
return false;
}
if (dir.equals(fTopLayer))
{
return true;
}
pos--;
}
return false;
}
/**
* Get the name of the current component.
* @return The name.
*/
public String getName()
{
return fComponents.get(fPosition).getName();
return fLayeredYet && fDirectlyContained;
}
/**
@@ -294,25 +251,15 @@ class Lookup
return fComponents.size();
}
/**
* Get the current position within the lookup.
* @return The current position.
*/
public int getPosition()
{
return fPosition;
}
/**
* Calculate the indirection path at this node.
* @return The indirection path all the way down to the current node.
*/
public String getIndirectionPath()
{
int lowestLayerIndex = fComponents.get(fPosition).getLowestLayerIndex();
// The path is the underlying path of the lowest layer that is directly contained
// by the top layer that is a primary indirection node.
for (int pos = lowestLayerIndex; pos >= fTopLayerIndex; pos--)
for (int pos = fLowestLayerIndex; pos >= fTopLayerIndex; pos--)
{
AVMNode node = fComponents.get(pos).getNode();
if (node.getType() != AVMNodeType.LAYERED_DIRECTORY)
@@ -390,15 +337,6 @@ class Lookup
return builder.toString();
}
/**
* Get whether the current node needs copying.
* @return Whether the current node needs copying.
*/
public boolean needsCopying()
{
return fComponents.get(fPosition).getNeedsCopy();
}
/**
* Acquire locks for writing, in path lookup order.
*/

View File

@@ -38,21 +38,6 @@ class LookupComponent
*/
private String fIndirection;
/**
* The lowest layer index.
*/
private int fLowestLayerIndex;
/**
* Whether this node is in a layer.
*/
private boolean fLayered;
/**
* Whether this needs copying.
*/
private boolean fNeedsCopy;
/**
* Create a new empty lookup component.
*/
@@ -78,45 +63,6 @@ class LookupComponent
fIndirection = indirection;
}
/**
* Is this component layered. I.e. has it seen a layer yet in
* its lookup.
* @return Whether this component is layered.
*/
public boolean isLayered()
{
return fLayered;
}
/**
* Set whether this node is layered.
* @param layered
*/
public void setLayered(boolean layered)
{
fLayered = layered;
}
/**
* Get the index of the lowest (in the path lookup sense) layer
* seen at this component's point in the lookup.
* @return the lowestLayerIndex
*/
public int getLowestLayerIndex()
{
return fLowestLayerIndex;
}
/**
* Set the index of the lowest (in the path lookup sense) layer
* seen at this components's point in the lookup.
* @param lowestLayerIndex the lowestLayerIndex to set
*/
public void setLowestLayerIndex(int lowestLayerIndex)
{
fLowestLayerIndex = lowestLayerIndex;
}
/**
* Get the path component name.
* @return the name
@@ -152,22 +98,4 @@ class LookupComponent
{
fNode = node;
}
/**
* Set the needs copy bit.
* @param needs Whether this component needs to be copied.
*/
public void setNeedsCopy(boolean needs)
{
fNeedsCopy = needs;
}
/**
* Does this component need a copy.
* @return Whether it does.
*/
public boolean getNeedsCopy()
{
return fNeedsCopy;
}
}

View File

@@ -40,7 +40,6 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory
{
super(repo.getSuperRepository().issueID(), repo);
repo.getSuperRepository().getSession().save(this);
SuperRepository.GetInstance().getSession().flush();
}
/**
@@ -62,7 +61,6 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory
super(repos.getSuperRepository().issueID(), repos);
Session sess = repos.getSuperRepository().getSession();
sess.save(this);
sess.flush();
for (ChildEntry child : other.getChildren())
{
ChildEntry newChild = new ChildEntryImpl(child.getName(),

View File

@@ -131,7 +131,7 @@ class RepositoryImpl implements Repository, Serializable
// If the root isn't new, we can't take a snapshot since nothing has changed.
if (!fRoot.getIsNew())
{
// TODO Silently return for now.
throw new AVMExistsException("Already snapshotted.");
}
// Clear out the new nodes.
Query query =

View File

@@ -32,7 +32,7 @@ public class SimultaneousLoadTest extends AVMServiceTestBase
{
try
{
int n = 2;
int n = 8;
int m = 1;
for (int i = 0; i < n; i++)
{
@@ -42,7 +42,7 @@ public class SimultaneousLoadTest extends AVMServiceTestBase
Thread [] threads = new Thread[n];
for (int i = 0; i < n; i++)
{
Loader loader = new Loader("source", "main:/d" + i, m);
Loader loader = new Loader("/Users/britt/stuff/" + i, "main:/d" + i, m);
threads[i] = new Thread(loader);
threads[i].start();
}

View File

@@ -112,11 +112,23 @@ public class HibernateTxn
{
if (t instanceof StaleStateException)
{
// System.err.println("Lost Race");
System.err.println("Lost Race");
StackTraceElement [] stack = t.getStackTrace();
long threadID = Thread.currentThread().getId();
for (StackTraceElement frame : stack)
{
System.err.println(threadID + " " + frame);
}
}
else
{
// System.err.println("Deadlock");
System.err.println("Deadlock");
StackTraceElement [] stack = t.getStackTrace();
long threadID = Thread.currentThread().getId();
for (StackTraceElement frame : stack)
{
System.err.println(threadID + " " + frame);
}
try
{
long interval;