Skip to content

Move grid file retrieval code up into (retried) init code #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Unmaintained
============
Note this is an unmaintained fork of Mike's original (also unmaintained) repo.
I've done /some/ work on it - namely solving the problem of stale sockets if mongodb restarts, as well as integrating some other pull requests that weren't in the original -
but last time I tried this module wouldn't compile against latest version of nginx (1.5.7).
I've since abandoned this approach, in favour of the node server here: https://github.com/rdkls/node-gridfs-http-frontend so won't be spending any more time trying to get it working. It's not far off though ...

nginx-gridfs
============
:Authors:
Expand Down
46 changes: 20 additions & 26 deletions ngx_http_gridfs_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -888,26 +888,6 @@ static ngx_int_t ngx_http_gridfs_handler(ngx_http_request_t* request) {

// ---------- RETRIEVE GRIDFILE ---------- //

do {
e = FALSE;
status = gridfs_init(&mongo_conn->conn,
(const char*)gridfs_conf->db.data,
(const char*)gridfs_conf->root_collection.data,
&gfs);
if (status != MONGO_OK) {
e = TRUE; ecounter++;
if (ecounter > MONGO_MAX_RETRIES_PER_REQUEST
|| ngx_http_mongo_reconnect(request->connection->log, mongo_conn) == NGX_ERROR
|| ngx_http_mongo_reauth(request->connection->log, mongo_conn) == NGX_ERROR) {
ngx_log_error(NGX_LOG_ERR, request->connection->log, 0,
"Mongo connection dropped, could not reconnect");
if(mongo_conn->conn.connected) { mongo_disconnect(&mongo_conn->conn); }
free(value);
return NGX_HTTP_SERVICE_UNAVAILABLE;
}
}
} while (e);

bson_init(&query);
switch (gridfs_conf->type) {
case BSON_OID:
Expand All @@ -923,16 +903,30 @@ static ngx_int_t ngx_http_gridfs_handler(ngx_http_request_t* request) {
}
bson_finish(&query);

status = gridfs_find_query(&gfs, &query, &gfile);
do {
e = FALSE;
if (gridfs_init(&mongo_conn->conn,
(const char*)gridfs_conf->db.data,
(const char*)gridfs_conf->root_collection.data,
&gfs) != MONGO_OK
|| (status = gridfs_find_query(&gfs, &query, &gfile) == MONGO_ERROR)) {
e = TRUE; ecounter++;
if (ecounter > MONGO_MAX_RETRIES_PER_REQUEST
|| ngx_http_mongo_reconnect(request->connection->log, mongo_conn) == NGX_ERROR
|| ngx_http_mongo_reauth(request->connection->log, mongo_conn) == NGX_ERROR) {
ngx_log_error(NGX_LOG_ERR, request->connection->log, 0,
"Mongo connection dropped, could not reconnect");
if(&mongo_conn->conn.connected) { mongo_disconnect(&mongo_conn->conn); }
bson_destroy(&query);
free(value);
return NGX_HTTP_SERVICE_UNAVAILABLE;
}
}
} while (e);

bson_destroy(&query);
free(value);

if(status == MONGO_ERROR) {
gridfs_destroy(&gfs);
return NGX_HTTP_NOT_FOUND;
}

/* Get information about the file */
length = gridfile_get_contentlength(&gfile);
numchunks = gridfile_get_numchunks(&gfile);
Expand Down