forked from bloomberg/comdb2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Morgan Douglas <mdouglas47@bloomberg.net>
- Loading branch information
Showing
7 changed files
with
243 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
#include <assert.h> | ||
#include <comdb2systblInt.h> | ||
#include <ezsystables.h> | ||
#include "files.h" | ||
|
||
static int filenamesBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo) | ||
{ | ||
const int rc = filesBestIndex(tab, pIdxInfo); | ||
assert(rc != SQLITE_OK | ||
|| pIdxInfo->idxNum == 0 | ||
|| pIdxInfo->idxNum == FILES_FILE_PATTERN_FLAG); | ||
|
||
return rc; | ||
} | ||
|
||
static int filenamesConnect(sqlite3 *db, void *pAux, int argc, | ||
const char *const *argv, sqlite3_vtab **ppVtab, | ||
char **pzErr) | ||
{ | ||
sqlite3_vtab *pNew; | ||
int rc; | ||
|
||
rc = sqlite3_declare_vtab( db, "CREATE TABLE x(filename, dir, type)"); | ||
if (rc == SQLITE_OK) { | ||
pNew = *ppVtab = sqlite3_malloc(sizeof(*pNew)); | ||
if (pNew == 0) return SQLITE_NOMEM; | ||
memset(pNew, 0, sizeof(*pNew)); | ||
} | ||
return rc; | ||
} | ||
|
||
static int filenamesDisconnect(sqlite3_vtab *pVtab) | ||
{ | ||
sqlite3_free(pVtab); | ||
return SQLITE_OK; | ||
} | ||
|
||
static int filenamesOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor) | ||
{ | ||
return filesOpen(p, ppCursor); | ||
} | ||
|
||
static int filenamesClose(sqlite3_vtab_cursor *cur) | ||
{ | ||
return filesClose(cur); | ||
} | ||
|
||
static int filenamesFilter(sqlite3_vtab_cursor *pVtabCursor, int idxNum, | ||
const char *idxStr, int argc, sqlite3_value **argv) | ||
{ | ||
assert(idxNum == 0 | ||
|| idxNum == FILES_FILE_PATTERN_FLAG); | ||
|
||
const int just_get_filenames = 1; | ||
return _filesFilter(pVtabCursor, idxNum, idxStr, argc, argv, just_get_filenames); | ||
} | ||
|
||
static int filenamesEof(sqlite3_vtab_cursor *cur) | ||
{ | ||
systbl_files_cursor *pCur = (systbl_files_cursor *)cur; | ||
return (pCur->rowid >= pCur->nfiles) ? 1 : 0; | ||
} | ||
|
||
static int filenamesNext(sqlite3_vtab_cursor *cur) | ||
{ | ||
systbl_files_cursor * const pCur = (systbl_files_cursor *) cur; | ||
logmsg(LOGMSG_DEBUG, "%s:%d done processing %s\n", __func__, __LINE__, | ||
pCur->files[pCur->rowid].name); | ||
++pCur->rowid; | ||
if (!filenamesEof(cur)) { | ||
logmsg(LOGMSG_DEBUG, "%s:%d processing %s\n", __func__, __LINE__, | ||
pCur->files[pCur->rowid].name); | ||
} | ||
return SQLITE_OK; | ||
} | ||
|
||
static int | ||
filenamesColumn(sqlite3_vtab_cursor *cur, /* The cursor */ | ||
sqlite3_context *ctx, /* First argument to sqlite3_result_...() */ | ||
int i /* Which column to return */ | ||
) { | ||
assert(i == FILES_COLUMN_FILENAME | ||
|| i == FILES_COLUMN_DIR | ||
|| i == FILES_COLUMN_TYPE); | ||
return filesColumn(cur, ctx, i); | ||
} | ||
|
||
static int filenamesRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid) | ||
{ | ||
systbl_files_cursor *pCur = (systbl_files_cursor *)cur; | ||
*pRowid = pCur->rowid; | ||
return SQLITE_OK; | ||
} | ||
|
||
/* | ||
** This following structure defines all the methods for the | ||
** generate_series virtual table. | ||
*/ | ||
const sqlite3_module systblFilenamesModule = { | ||
0, /* iVersion */ | ||
0, /* xCreate */ | ||
filenamesConnect, /* xConnect */ | ||
filenamesBestIndex, /* xBestIndex */ | ||
filenamesDisconnect, /* xDisconnect */ | ||
0, /* xDestroy */ | ||
filenamesOpen, /* xOpen - open a cursor */ | ||
filenamesClose, /* xClose - close a cursor */ | ||
filenamesFilter, /* xFilter - configure scan constraints */ | ||
filenamesNext, /* xNext - advance a cursor */ | ||
filenamesEof, /* xEof - check for end of scan */ | ||
filenamesColumn, /* xColumn - read data */ | ||
filenamesRowid, /* xRowid - read data */ | ||
0, /* xUpdate */ | ||
0, /* xBegin */ | ||
0, /* xSync */ | ||
0, /* xCommit */ | ||
0, /* xRollback */ | ||
0, /* xFindMethod */ | ||
0, /* xRename */ | ||
0, /* xSavepoint */ | ||
0, /* xRelease */ | ||
0, /* xRollbackTo */ | ||
0, /* xShadowName */ | ||
.access_flag = CDB2_ALLOW_USER}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#ifndef __COMDB2_FILES_H_ | ||
#define __COMDB2_FILES_H_ | ||
|
||
#include <comdb2.h> | ||
#include "list.h" | ||
#include "ar_wrap.h" | ||
|
||
/* Column numbers */ | ||
enum { | ||
FILES_COLUMN_FILENAME, | ||
FILES_COLUMN_DIR, | ||
FILES_COLUMN_TYPE, | ||
FILES_COLUMN_CONTENT, | ||
FILES_COLUMN_CONTENT_OFFSET, | ||
FILES_COLUMN_CONTENT_SIZE, | ||
FILES_COLUMN_CHUNK_SIZE, | ||
}; | ||
|
||
enum { | ||
FILES_FILE_PATTERN_FLAG = 1, | ||
FILES_CHUNK_SIZE_FLAG = 2, | ||
}; | ||
|
||
enum { | ||
FILES_TYPE_UNKNOWN, | ||
FILES_TYPE_CHECKPOINT, | ||
FILES_TYPE_BERKDB, | ||
FILES_TYPE_LOGFILE, /* Always keep LOGFILE in the end for them to sort | ||
higher */ | ||
}; | ||
|
||
typedef struct db_chunk { | ||
uint8_t *buffer; | ||
size_t size; | ||
size_t offset; | ||
LINKC_T(struct db_chunk) lnk; | ||
} db_chunk_t; | ||
|
||
typedef struct db_file { | ||
char *name; /* Name of the file */ | ||
char *dir; /* Name of the directory */ | ||
int type; | ||
int chunk_seq; | ||
struct db_chunk current_chunk; | ||
dbfile_info *info; | ||
} db_file_t; | ||
|
||
typedef struct { | ||
sqlite3_vtab_cursor base; | ||
sqlite3_int64 rowid; | ||
db_file_t *files; | ||
size_t nfiles; | ||
off_t content_offset; | ||
size_t content_size; | ||
size_t chunk_size; | ||
char *file_pattern; | ||
struct log_delete_state log_delete_state; | ||
} systbl_files_cursor; | ||
|
||
int get_files(void **data, size_t *npoints, char *file_pattern, size_t chunk_size); | ||
int filesOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor); | ||
int filesClose(sqlite3_vtab_cursor *cur); | ||
int filesColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i); | ||
int filesBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo); | ||
int _filesFilter(sqlite3_vtab_cursor *pVtabCursor, int idxNum, | ||
const char *idxStr, int argc, sqlite3_value **argv, const int just_get_filenames); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.