Ejemplo n.º 1
0
int memsector_load(memsector_handle_t *ms, const char *path) {
    int status;

    // load memory map
    status = mmap_load(path, MAP_SHARED, &ms->mmap_handle);
    if (status == -1) {
        return -1;
    }

    // read and validate memsector data
    memsector_header_t* memsector =
            (memsector_header_t*) ms->mmap_handle.start_addr;
    if (memsector->magic != MEMSECTOR_MAGIC) {
        PRINT_WARN("File %s is not a memsector (magic mismatch)\n", path);
        mmap_unload(&ms->mmap_handle);
        return -1;
    }
    if (memsector->version != MEMSECTOR_VERSION) {
        PRINT_WARN("Cannot process memsector %s v%d\n",
                   path, (int) memsector->version);
        mmap_unload(&ms->mmap_handle);
        return -1;
    }
    if (memsector->checksum != memsector_get_checksum(memsector)) {
        PRINT_WARN("Memsector %s is corrupted (checksum mismatch)\n", path);
        mmap_unload(&ms->mmap_handle);
        return -1;
    }

    // initialize handle data
    ms->ms = memsector;

    return 0;
}
Ejemplo n.º 2
0
void ZipIntKeyIndex::load(PathRef path) {
	auto fpath = path + ".zint";
	m_mmapBase = (byte_t*)mmap_load(fpath.string(), &m_mmapSize);
	auto h = (const Header*)m_mmapBase;
	m_isUnique   = h->isUnique ? true : false;
	m_keyType    = ColumnType(h->keyType);
	m_minKey     = h->minKey;
	size_t indexBits = terark_bsr_u64(h->rows - 1) + 1;
	m_keys .risk_set_data((byte*)(h+1)                    , h->rows, h->keyBits);
	m_index.risk_set_data((byte*)(h+1) + m_keys.mem_size(), h->rows,  indexBits);
}
Ejemplo n.º 3
0
	explicit MmapWholeFile(const String& fname,
						   bool writable = false,
						   bool populate = false) {
		base = mmap_load(fname, &size, writable, populate);
	}
Ejemplo n.º 4
0
void* mmap_load(const String& fname, size_t* size,
				bool writable = false,
				bool populate = false) {
	return mmap_load(fname.c_str(), size, writable, populate);
}
Ejemplo n.º 5
0
void* mmap_load(const String& fname, size_t* size) {
	return mmap_load(fname.c_str(), size);
}