removed some unnecessary synchronizations

pull/1/head
Michael Peter Christen 12 years ago
parent 9bd2aee180
commit 442ed50be0

@ -102,7 +102,7 @@ public class EmbeddedSolrConnector extends SolrServerConnector implements SolrCo
* because we can do this with more efficiently in a different way for embedded indexes. * because we can do this with more efficiently in a different way for embedded indexes.
*/ */
@Override @Override
public synchronized long getSize() { public long getSize() {
String threadname = Thread.currentThread().getName(); String threadname = Thread.currentThread().getName();
Thread.currentThread().setName("solr query: size"); Thread.currentThread().setName("solr query: size");
EmbeddedSolrServer ess = (EmbeddedSolrServer) this.server; EmbeddedSolrServer ess = (EmbeddedSolrServer) this.server;
@ -154,7 +154,7 @@ public class EmbeddedSolrConnector extends SolrServerConnector implements SolrCo
return req; return req;
} }
public synchronized SolrQueryResponse query(SolrQueryRequest req) throws SolrException { public SolrQueryResponse query(SolrQueryRequest req) throws SolrException {
final long startTime = System.currentTimeMillis(); final long startTime = System.currentTimeMillis();
// during the solr query we set the thread name to the query string to get more debugging info in thread dumps // during the solr query we set the thread name to the query string to get more debugging info in thread dumps
@ -191,9 +191,7 @@ public class EmbeddedSolrConnector extends SolrServerConnector implements SolrCo
String threadname = Thread.currentThread().getName(); String threadname = Thread.currentThread().getName();
if (q != null) Thread.currentThread().setName("solr query: q = " + q); if (q != null) Thread.currentThread().setName("solr query: q = " + q);
QueryResponse rsp; QueryResponse rsp;
synchronized (this) { rsp = this.server.query(params);
rsp = this.server.query(params);
}
if (q != null) Thread.currentThread().setName(threadname); if (q != null) Thread.currentThread().setName(threadname);
if (rsp != null) log.info(rsp.getResults().getNumFound() + " results for q=" + q); if (rsp != null) log.info(rsp.getResults().getNumFound() + " results for q=" + q);
return rsp; return rsp;

@ -91,7 +91,7 @@ public abstract class SolrServerConnector extends AbstractSolrConnector implemen
} }
@Override @Override
public synchronized long getSize() { public long getSize() {
try { try {
final QueryResponse rsp = getResponseByParams(AbstractSolrConnector.catchSuccessQuery); final QueryResponse rsp = getResponseByParams(AbstractSolrConnector.catchSuccessQuery);
if (rsp == null) return 0; if (rsp == null) return 0;
@ -119,7 +119,7 @@ public abstract class SolrServerConnector extends AbstractSolrConnector implemen
} }
@Override @Override
public synchronized void deleteById(final String id) throws IOException { public void deleteById(final String id) throws IOException {
try { try {
this.server.deleteById(id, -1); this.server.deleteById(id, -1);
} catch (final Throwable e) { } catch (final Throwable e) {
@ -128,7 +128,7 @@ public abstract class SolrServerConnector extends AbstractSolrConnector implemen
} }
@Override @Override
public synchronized void deleteByIds(final Collection<String> ids) throws IOException { public void deleteByIds(final Collection<String> ids) throws IOException {
List<String> l = new ArrayList<String>(); List<String> l = new ArrayList<String>();
for (String s: ids) l.add(s); for (String s: ids) l.add(s);
try { try {
@ -144,7 +144,7 @@ public abstract class SolrServerConnector extends AbstractSolrConnector implemen
* @throws IOException * @throws IOException
*/ */
@Override @Override
public synchronized void deleteByQuery(final String querystring) throws IOException { public void deleteByQuery(final String querystring) throws IOException {
try { try {
this.server.deleteByQuery(querystring, -1); this.server.deleteByQuery(querystring, -1);
} catch (final Throwable e) { } catch (final Throwable e) {
@ -161,9 +161,7 @@ public abstract class SolrServerConnector extends AbstractSolrConnector implemen
up.setCommitWithin(-1); up.setCommitWithin(-1);
//up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true); //up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
try { try {
synchronized (this.server) { this.server.request(up);
this.server.request(up);
}
} catch (final Throwable e) { } catch (final Throwable e) {
throw new IOException(e); throw new IOException(e);
} }
@ -174,20 +172,14 @@ public abstract class SolrServerConnector extends AbstractSolrConnector implemen
if (this.server == null) return; if (this.server == null) return;
try { try {
if (solrdoc.containsKey("_version_")) solrdoc.setField("_version_",0L); // prevent Solr "version conflict" if (solrdoc.containsKey("_version_")) solrdoc.setField("_version_",0L); // prevent Solr "version conflict"
synchronized (this.server) {
this.server.add(solrdoc, -1); this.server.add(solrdoc, -1);
}
} catch (Throwable e) { } catch (Throwable e) {
// catches "version conflict for": try this again and delete the document in advance // catches "version conflict for": try this again and delete the document in advance
try { try {
synchronized (this.server) { this.server.deleteById((String) solrdoc.getFieldValue(CollectionSchema.id.getSolrFieldName()));
this.server.deleteById((String) solrdoc.getFieldValue(CollectionSchema.id.getSolrFieldName()));
}
} catch (SolrServerException e1) {} } catch (SolrServerException e1) {}
try { try {
synchronized (this.server) { this.server.add(solrdoc, -1);
this.server.add(solrdoc, -1);
}
} catch (Throwable ee) { } catch (Throwable ee) {
throw new IOException(ee); throw new IOException(ee);
} }
@ -201,22 +193,16 @@ public abstract class SolrServerConnector extends AbstractSolrConnector implemen
for (SolrInputDocument solrdoc : solrdocs) { for (SolrInputDocument solrdoc : solrdocs) {
if (solrdoc.containsKey("_version_")) solrdoc.setField("_version_",0L); // prevent Solr "version conflict" if (solrdoc.containsKey("_version_")) solrdoc.setField("_version_",0L); // prevent Solr "version conflict"
} }
synchronized (this.server) { this.server.add(solrdocs, -1);
this.server.add(solrdocs, -1);
}
} catch (Throwable e) { } catch (Throwable e) {
// catches "version conflict for": try this again and delete the document in advance // catches "version conflict for": try this again and delete the document in advance
List<String> ids = new ArrayList<String>(); List<String> ids = new ArrayList<String>();
for (SolrInputDocument solrdoc : solrdocs) ids.add((String) solrdoc.getFieldValue(CollectionSchema.id.getSolrFieldName())); for (SolrInputDocument solrdoc : solrdocs) ids.add((String) solrdoc.getFieldValue(CollectionSchema.id.getSolrFieldName()));
try { try {
synchronized (this.server) { this.server.deleteById(ids);
this.server.deleteById(ids);
}
} catch (SolrServerException e1) {} } catch (SolrServerException e1) {}
try { try {
synchronized (this.server) { this.server.add(solrdocs, -1);
this.server.add(solrdocs, -1);
}
} catch (Throwable ee) { } catch (Throwable ee) {
log.warn(e.getMessage() + " IDs=" + ids.toString()); log.warn(e.getMessage() + " IDs=" + ids.toString());
throw new IOException(ee); throw new IOException(ee);

Loading…
Cancel
Save