upload-pack: Delay reserving database connection until executing
We don't want to check out a connection from the connection pool until we know we have been granted a thread from the thread pool to execute on. If we grab the connection when the Upload object is created, and we have to wait 5 seconds to get a thread for runImpl() to execute on, we'll simply be tieing up that connection for the entire duration of the wait. So use a Provider instead so we can defer obtaining the connection. Change-Id: I9ac360981fb1ad3e09e77ad579e9203686b14494 Signed-off-by: Shawn O. Pearce <sop@google.com> Reviewed-by: Nico Sallembien <nsallembien@google.com>
This commit is contained in:
@@ -18,6 +18,7 @@ import com.google.gerrit.reviewdb.ReviewDb;
|
||||
import com.google.gerrit.server.git.VisibleRefFilter;
|
||||
import com.google.gerrit.sshd.AbstractGitCommand;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import org.eclipse.jgit.transport.UploadPack;
|
||||
|
||||
@@ -25,15 +26,14 @@ import java.io.IOException;
|
||||
|
||||
/** Publishes Git repositories over SSH using the Git upload-pack protocol. */
|
||||
final class Upload extends AbstractGitCommand {
|
||||
|
||||
@Inject
|
||||
private ReviewDb db;
|
||||
private Provider<ReviewDb> db;
|
||||
|
||||
@Override
|
||||
protected void runImpl() throws IOException {
|
||||
final UploadPack up = new UploadPack(repo);
|
||||
if (!projectControl.allRefsAreVisible()) {
|
||||
up.setRefFilter(new VisibleRefFilter(repo, projectControl, db));
|
||||
up.setRefFilter(new VisibleRefFilter(repo, projectControl, db.get()));
|
||||
}
|
||||
up.upload(in, out, err);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user