Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
remove synchronous updateRepositroySize code; calculating the reposit…
…ory size is now done by querying the JCR index
  • Loading branch information
cbeer committed Apr 16, 2013
1 parent 7eb45d0 commit efc3e77
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 85 deletions.
Expand Up @@ -123,8 +123,6 @@ public void deleteObject(String pid, Session session)
long objSize = getObjectSize(obj);
obj.remove();
session.save();
updateRepositorySize(0L - objSize, session);
session.save();
}

}
Expand Up @@ -55,41 +55,6 @@ public static void dumpMetrics(PrintStream os) {
RegistryService.dumpMetrics(os);
}

/**
* Alter the total repository size.
*
* @param change
* the amount by which to [de|in]crement the total repository
* size
* @param session
* the javax.jcr.Session in which the originating mutation is
* occurring
* @throws PathNotFoundException
* @throws RepositoryException
*/
public void updateRepositorySize(Long change, Session session)
throws PathNotFoundException, RepositoryException {
try {
logger.debug("updateRepositorySize called with change quantity: " +
change);

final Node objectStore = findOrCreateNode(session, "/objects");

Property sizeProperty = objectStore.getProperty(FEDORA_SIZE);

Long previousSize = sizeProperty.getLong();
logger.debug("Previous repository size: " + previousSize);
synchronized (sizeProperty) {
sizeProperty.setValue(previousSize + change);
session.save();
}
logger.debug("Current repository size: " + sizeProperty.getLong());
} catch (RepositoryException e) {
logger.warn(e.toString());
throw e;
}
}

/**
*
* @return a double of the size of the fedora:datastream binary content
Expand Down
Expand Up @@ -123,19 +123,14 @@ public void testDeleteOBject() throws RepositoryException {
Session mockSession = mock(Session.class);
Node mockRootNode = mock(Node.class);
Node mockObjectsNode = mock(Node.class);
Property mockProp = mock(Property.class);
Node mockObjNode = mock(Node.class);
when(mockObjectsNode.getProperty(FEDORA_SIZE)).thenReturn(mockProp);
when(mockSession.getRootNode()).thenReturn(mockRootNode);
when(mockRootNode.getNode("objects")).thenReturn(mockObjectsNode);
when(mockSession.getNode(objPath)).thenReturn(mockObjNode);
PowerMockito.mockStatic(ServiceHelpers.class);
long mockSize = new SecureRandom().nextLong();
when(ServiceHelpers.getObjectSize(mockObjNode)).thenReturn(mockSize); // testing with a random value
ObjectService testObj = new ObjectService();
testObj.deleteObject("foo", mockSession);
verify(mockSession).getNode(objPath);
verify(mockObjNode).remove();
verify(mockProp).setValue(0 - mockSize);
}
}
Expand Up @@ -148,16 +148,6 @@ public void testDumpMetrics() {
RepositoryService.dumpMetrics(mockPrintStream);
}

@Test
public void testUpdateRepositorySize() throws PathNotFoundException,
RepositoryException {
String content = "asdf";
Node mockContent = getContentNodeMock(content);
when(mockDsNode.getNode(JCR_CONTENT)).thenReturn(mockContent);
testObj.updateRepositorySize(expectedSize, mockSession);
assertEquals(expectedSize, testObj.getRepositorySize(mockSession));
}

@Test
public void testGetRepositorySize() throws RepositoryException {
Long actual = testObj.getRepositorySize(mockSession);
Expand Down
Expand Up @@ -128,16 +128,6 @@ public Response addDatastreams(@PathParam("pid")
}
session.save();

/*
* we save before updating the repo size because the act of
* persisting session state creates new system-curated nodes and
* properties which contribute to the footprint of this resource
*/
datastreamService.updateRepositorySize(getObjectSize(session
.getNode(getObjectJcrNodePath(pid))) -
oldObjectSize, session);
// now we save again to persist the repo size
session.save();
} finally {
session.logout();
}
Expand Down Expand Up @@ -335,18 +325,6 @@ private URI addDatastreamNode(final String pid, final String dsPath,
.toString(), requestBodyStream);
boolean created = session.nodeExists(dsPath);
session.save();
if (created) {
/*
* we save before updating the repo size because the act of
* persisting session state creates new system-curated nodes and
* properties which contribute to the footprint of this resource
*/
datastreamService.updateRepositorySize(getObjectSize(session
.getNode(getObjectJcrNodePath(pid))) -
oldObjectSize, session);
// now we save again to persist the repo size
session.save();
}
} finally {
session.logout();
}
Expand Down Expand Up @@ -471,8 +449,6 @@ public Response deleteDatastream(@PathParam("pid")
final String dsPath = getDatastreamJcrNodePath(pid, dsid);
final Session session = getAuthenticatedSession();
final Node ds = session.getNode(dsPath);
datastreamService.updateRepositorySize(0L - getDatastreamSize(ds),
session);
return deleteResource(ds);
}

Expand Down
Expand Up @@ -119,14 +119,6 @@ public Response ingest(@PathParam("pid")
try {
final Node obj = objectService.createObjectNode(session, pid);
session.save();
/*
* we save before updating the repo size because the act of
* persisting session state creates new system-curated nodes and
* properties which contribute to the footprint of this resource
*/
objectService.updateRepositorySize(getObjectSize(obj), session);
// now we save again to persist the repo size
session.save();
logger.debug("Finished ingest with pid: " + pid);
return created(uriInfo.getAbsolutePath()).entity(pid).build();

Expand Down Expand Up @@ -191,7 +183,6 @@ public Response deleteObject(@PathParam("pid")
final String pid) throws RepositoryException {
final Session session = getAuthenticatedSession();
final Node obj = session.getNode(getObjectJcrNodePath(pid));
objectService.updateRepositorySize(0L - getObjectSize(obj), session);
return deleteResource(obj);
}

Expand Down

0 comments on commit efc3e77

Please sign in to comment.