2006-07-17 19:44:18 +02:00
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Initial
|
|
|
|
* Developer's Public License Version 1.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed AS IS,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing rights
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code was created by Dmitry Yemanov
|
|
|
|
* for the Firebird Open Source RDBMS project.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006 Dmitry Yemanov <dimitr@users.sf.net>
|
|
|
|
* and all contributors signed below.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "firebird.h"
|
|
|
|
#include "ids.h"
|
2006-10-30 13:39:08 +01:00
|
|
|
|
|
|
|
#include "../common/classes/auto.h"
|
|
|
|
#include "../common/classes/locks.h"
|
|
|
|
|
2006-07-17 19:44:18 +02:00
|
|
|
#include "../jrd/gdsassert.h"
|
|
|
|
#include "../jrd/jrd.h"
|
|
|
|
#include "../jrd/cch.h"
|
|
|
|
#include "../jrd/ini.h"
|
2007-09-14 17:39:53 +02:00
|
|
|
#include "../jrd/nbak.h"
|
2006-10-30 13:39:08 +01:00
|
|
|
#include "../jrd/os/guid.h"
|
2006-07-17 19:44:18 +02:00
|
|
|
#include "../jrd/os/pio.h"
|
|
|
|
#include "../jrd/req.h"
|
|
|
|
#include "../jrd/tra.h"
|
|
|
|
#include "../jrd/blb_proto.h"
|
2006-10-30 13:39:08 +01:00
|
|
|
#include "../jrd/isc_proto.h"
|
2009-07-11 21:58:28 +02:00
|
|
|
#include "../jrd/isc_f_proto.h"
|
2006-10-30 13:39:08 +01:00
|
|
|
#include "../jrd/isc_s_proto.h"
|
|
|
|
#include "../jrd/lck_proto.h"
|
2006-07-17 19:44:18 +02:00
|
|
|
#include "../jrd/met_proto.h"
|
2009-07-06 11:19:26 +02:00
|
|
|
#include "../jrd/mov_proto.h"
|
2006-07-17 19:44:18 +02:00
|
|
|
#include "../jrd/os/pio_proto.h"
|
2006-12-04 22:36:29 +01:00
|
|
|
#include "../jrd/pag_proto.h"
|
2006-10-30 13:39:08 +01:00
|
|
|
#include "../jrd/thread_proto.h"
|
2006-07-17 19:44:18 +02:00
|
|
|
|
|
|
|
#include "../jrd/Relation.h"
|
|
|
|
#include "../jrd/RecordBuffer.h"
|
|
|
|
#include "../jrd/DatabaseSnapshot.h"
|
|
|
|
|
2008-05-06 10:46:39 +02:00
|
|
|
#include "../common/utils_proto.h"
|
|
|
|
|
2006-08-25 06:57:14 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2006-10-30 13:39:08 +01:00
|
|
|
#ifdef UNIX
|
|
|
|
#include <signal.h>
|
|
|
|
#endif
|
|
|
|
|
2006-08-25 06:57:14 +02:00
|
|
|
#ifdef WIN_NT
|
|
|
|
#include <process.h>
|
2006-10-30 13:39:08 +01:00
|
|
|
#include <windows.h>
|
2006-08-25 06:57:14 +02:00
|
|
|
#endif
|
|
|
|
|
2009-08-19 11:35:03 +02:00
|
|
|
#ifdef SUPERSERVER
|
2009-08-20 03:32:24 +02:00
|
|
|
static const bool SHARED_DBB = true;
|
2009-08-19 11:35:03 +02:00
|
|
|
#else
|
2009-08-20 03:32:24 +02:00
|
|
|
static const bool SHARED_DBB = false;
|
2009-08-19 11:35:03 +02:00
|
|
|
#endif
|
|
|
|
|
2006-10-30 13:39:08 +01:00
|
|
|
|
|
|
|
using namespace Firebird;
|
2006-07-17 19:44:18 +02:00
|
|
|
using namespace Jrd;
|
|
|
|
|
2006-10-30 13:39:08 +01:00
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
// SharedData class
|
2006-10-30 13:39:08 +01:00
|
|
|
|
2009-01-28 13:27:18 +01:00
|
|
|
DatabaseSnapshot::SharedData::SharedData(const Database* dbb)
|
|
|
|
: process_id(getpid()), local_id(dbb->dbb_monitoring_id)
|
2006-10-30 13:39:08 +01:00
|
|
|
{
|
2009-01-29 18:44:21 +01:00
|
|
|
string name;
|
2009-01-28 13:27:18 +01:00
|
|
|
name.printf(MONITOR_FILE, dbb->getUniqueFileId().c_str());
|
2006-10-30 13:39:08 +01:00
|
|
|
|
|
|
|
ISC_STATUS_ARRAY statusVector;
|
2009-01-28 13:27:18 +01:00
|
|
|
base = (Header*) ISC_map_file(statusVector, name.c_str(), init, this, DEFAULT_SIZE, &handle);
|
2006-10-30 13:39:08 +01:00
|
|
|
if (!base)
|
|
|
|
{
|
2008-12-04 11:44:16 +01:00
|
|
|
iscLogStatus("Cannot initialize the shared memory region", statusVector);
|
2006-10-30 13:39:08 +01:00
|
|
|
status_exception::raise(statusVector);
|
|
|
|
}
|
|
|
|
|
2009-01-28 13:27:18 +01:00
|
|
|
fb_assert(base->version == MONITOR_VERSION);
|
2006-10-30 13:39:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-28 13:27:18 +01:00
|
|
|
DatabaseSnapshot::SharedData::~SharedData()
|
2006-10-30 13:39:08 +01:00
|
|
|
{
|
2009-07-06 11:19:26 +02:00
|
|
|
{ // scope
|
|
|
|
DumpGuard guard(this);
|
|
|
|
cleanup();
|
2010-06-05 04:41:14 +02:00
|
|
|
|
|
|
|
if (base->used == sizeof(Header))
|
|
|
|
ISC_remove_map_file(&handle);
|
2009-07-06 11:19:26 +02:00
|
|
|
}
|
2009-01-28 13:27:18 +01:00
|
|
|
|
2010-06-08 13:40:58 +02:00
|
|
|
ISC_mutex_fini(mutex);
|
2006-10-30 13:39:08 +01:00
|
|
|
ISC_STATUS_ARRAY statusVector;
|
2008-06-26 13:23:40 +02:00
|
|
|
ISC_unmap_file(statusVector, &handle);
|
2006-10-30 13:39:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-28 13:27:18 +01:00
|
|
|
void DatabaseSnapshot::SharedData::acquire()
|
2006-10-30 13:39:08 +01:00
|
|
|
{
|
2010-06-08 13:40:58 +02:00
|
|
|
checkMutex("lock", ISC_mutex_lock(mutex));
|
|
|
|
|
2008-02-06 14:47:08 +01:00
|
|
|
if (base->allocated > handle.sh_mem_length_mapped)
|
|
|
|
{
|
|
|
|
#if (defined HAVE_MMAP || defined WIN_NT)
|
|
|
|
ISC_STATUS_ARRAY statusVector;
|
2010-07-16 09:20:55 +02:00
|
|
|
base = (Header*) ISC_remap_file(statusVector, &handle, base->allocated, false, &mutex);
|
2008-02-06 14:47:08 +01:00
|
|
|
if (!base)
|
|
|
|
{
|
2008-12-20 09:12:19 +01:00
|
|
|
status_exception::raise(statusVector);
|
2008-02-06 14:47:08 +01:00
|
|
|
}
|
|
|
|
#else
|
2008-12-20 09:12:19 +01:00
|
|
|
status_exception::raise(Arg::Gds(isc_montabexh));
|
2008-02-06 14:47:08 +01:00
|
|
|
#endif
|
|
|
|
}
|
2006-10-30 13:39:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-28 13:27:18 +01:00
|
|
|
void DatabaseSnapshot::SharedData::release()
|
2006-10-30 13:39:08 +01:00
|
|
|
{
|
2010-06-08 13:40:58 +02:00
|
|
|
checkMutex("unlock", ISC_mutex_unlock(mutex));
|
2006-10-30 13:39:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-28 13:27:18 +01:00
|
|
|
UCHAR* DatabaseSnapshot::SharedData::read(MemoryPool& pool, ULONG& resultSize)
|
2006-10-30 13:39:08 +01:00
|
|
|
{
|
2008-12-25 07:30:01 +01:00
|
|
|
ULONG self_dbb_offset = 0;
|
2008-12-24 14:34:12 +01:00
|
|
|
|
2008-12-11 12:58:50 +01:00
|
|
|
// Garbage collect elements belonging to dead processes.
|
|
|
|
// This is done in two passes. First, we compact the data
|
|
|
|
// and calculate the total size of the resulting data.
|
2008-12-24 14:34:12 +01:00
|
|
|
// Second, we create a resulting buffer of the necessary size
|
|
|
|
// and copy the data there, starting with our own dbb.
|
2006-10-30 13:39:08 +01:00
|
|
|
|
2008-12-11 12:58:50 +01:00
|
|
|
// First pass
|
2009-07-20 15:44:02 +02:00
|
|
|
for (ULONG offset = alignOffset(sizeof(Header)); offset < base->used;)
|
2008-12-11 12:58:50 +01:00
|
|
|
{
|
|
|
|
UCHAR* const ptr = (UCHAR*) base + offset;
|
|
|
|
const Element* const element = (Element*) ptr;
|
2009-07-20 15:44:02 +02:00
|
|
|
const ULONG length = alignOffset(sizeof(Element) + element->length);
|
2006-10-30 13:39:08 +01:00
|
|
|
|
2009-01-28 13:27:18 +01:00
|
|
|
if (element->processId == process_id && element->localId == local_id)
|
2008-12-24 14:34:12 +01:00
|
|
|
{
|
|
|
|
self_dbb_offset = offset;
|
|
|
|
}
|
|
|
|
|
2008-12-11 12:58:50 +01:00
|
|
|
if (ISC_check_process_existence(element->processId))
|
|
|
|
{
|
|
|
|
resultSize += element->length;
|
|
|
|
offset += length;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-12-13 10:19:55 +01:00
|
|
|
fb_assert(base->used >= offset + length);
|
2008-12-11 12:58:50 +01:00
|
|
|
memmove(ptr, ptr + length, base->used - offset - length);
|
|
|
|
base->used -= length;
|
|
|
|
}
|
|
|
|
}
|
2006-10-30 13:39:08 +01:00
|
|
|
|
2008-12-24 14:34:12 +01:00
|
|
|
// Second pass
|
2008-12-13 10:19:55 +01:00
|
|
|
UCHAR* const buffer = FB_NEW(pool) UCHAR[resultSize];
|
|
|
|
UCHAR* bufferPtr(buffer);
|
2006-10-30 13:39:08 +01:00
|
|
|
|
2008-12-24 14:34:12 +01:00
|
|
|
fb_assert(self_dbb_offset);
|
|
|
|
|
|
|
|
UCHAR* const ptr = (UCHAR*) base + self_dbb_offset;
|
|
|
|
const Element* const element = (Element*) ptr;
|
|
|
|
memcpy(bufferPtr, ptr + sizeof(Element), element->length);
|
|
|
|
bufferPtr += element->length;
|
|
|
|
|
2009-07-20 15:44:02 +02:00
|
|
|
for (ULONG offset = alignOffset(sizeof(Header)); offset < base->used;)
|
2006-10-30 13:39:08 +01:00
|
|
|
{
|
2008-12-11 12:58:50 +01:00
|
|
|
UCHAR* const ptr = (UCHAR*) base + offset;
|
|
|
|
const Element* const element = (Element*) ptr;
|
2009-07-20 15:44:02 +02:00
|
|
|
const ULONG length = alignOffset(sizeof(Element) + element->length);
|
2008-12-11 12:58:50 +01:00
|
|
|
|
2008-12-24 14:34:12 +01:00
|
|
|
if (offset != self_dbb_offset)
|
|
|
|
{
|
|
|
|
memcpy(bufferPtr, ptr + sizeof(Element), element->length);
|
|
|
|
bufferPtr += element->length;
|
|
|
|
}
|
|
|
|
|
2008-12-11 12:58:50 +01:00
|
|
|
offset += length;
|
2006-10-30 13:39:08 +01:00
|
|
|
}
|
|
|
|
|
2008-12-13 10:19:55 +01:00
|
|
|
fb_assert(buffer + resultSize == bufferPtr);
|
2008-12-15 07:11:49 +01:00
|
|
|
return buffer;
|
2006-10-30 13:39:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
ULONG DatabaseSnapshot::SharedData::setup()
|
2006-10-30 13:39:08 +01:00
|
|
|
{
|
2009-07-06 11:19:26 +02:00
|
|
|
ensureSpace(sizeof(Element));
|
|
|
|
|
|
|
|
// Put an up-to-date element at the tail
|
|
|
|
const ULONG offset = base->used;
|
|
|
|
UCHAR* const ptr = (UCHAR*) base + offset;
|
|
|
|
Element* const element = (Element*) ptr;
|
|
|
|
element->processId = process_id;
|
|
|
|
element->localId = local_id;
|
|
|
|
element->length = 0;
|
2009-07-20 15:44:02 +02:00
|
|
|
base->used += alignOffset(sizeof(Element));
|
2009-07-06 11:19:26 +02:00
|
|
|
return offset;
|
|
|
|
}
|
2006-10-31 16:49:31 +01:00
|
|
|
|
2006-10-30 13:39:08 +01:00
|
|
|
|
2009-07-07 07:17:55 +02:00
|
|
|
void DatabaseSnapshot::SharedData::write(ULONG offset, ULONG length, const void* buffer)
|
2009-07-06 11:19:26 +02:00
|
|
|
{
|
|
|
|
ensureSpace(length);
|
2008-12-11 12:58:50 +01:00
|
|
|
|
|
|
|
// Put an up-to-date element at the tail
|
2009-07-07 07:17:55 +02:00
|
|
|
UCHAR* const ptr = (UCHAR*) base + offset;
|
2008-12-11 12:58:50 +01:00
|
|
|
Element* const element = (Element*) ptr;
|
2009-07-06 11:19:26 +02:00
|
|
|
memcpy(ptr + sizeof(Element) + element->length, buffer, length);
|
2009-07-20 15:44:02 +02:00
|
|
|
ULONG previous = alignOffset(sizeof(Element) + element->length);
|
2009-07-06 11:19:26 +02:00
|
|
|
element->length += length;
|
2009-07-20 15:44:02 +02:00
|
|
|
ULONG current = alignOffset(sizeof(Element) + element->length);
|
|
|
|
base->used += (current - previous);
|
2006-10-30 13:39:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-28 13:27:18 +01:00
|
|
|
void DatabaseSnapshot::SharedData::cleanup()
|
2008-12-12 17:04:57 +01:00
|
|
|
{
|
|
|
|
// Remove information about our dbb
|
2009-07-20 15:44:02 +02:00
|
|
|
for (ULONG offset = alignOffset(sizeof(Header)); offset < base->used;)
|
2008-12-12 17:04:57 +01:00
|
|
|
{
|
|
|
|
UCHAR* const ptr = (UCHAR*) base + offset;
|
|
|
|
const Element* const element = (Element*) ptr;
|
2009-07-20 15:44:02 +02:00
|
|
|
const ULONG length = alignOffset(sizeof(Element) + element->length);
|
2008-12-12 17:04:57 +01:00
|
|
|
|
2009-01-28 13:27:18 +01:00
|
|
|
if (element->processId == process_id && element->localId == local_id)
|
2008-12-12 17:04:57 +01:00
|
|
|
{
|
2008-12-16 12:02:25 +01:00
|
|
|
fb_assert(base->used >= offset + length);
|
2008-12-12 17:04:57 +01:00
|
|
|
memmove(ptr, ptr + length, base->used - offset - length);
|
|
|
|
base->used -= length;
|
|
|
|
}
|
2008-12-13 10:19:55 +01:00
|
|
|
else
|
2008-12-16 12:02:25 +01:00
|
|
|
{
|
2008-12-13 10:19:55 +01:00
|
|
|
offset += length;
|
2008-12-16 12:02:25 +01:00
|
|
|
}
|
2008-12-12 17:04:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
void DatabaseSnapshot::SharedData::ensureSpace(ULONG length)
|
2006-10-30 13:39:08 +01:00
|
|
|
{
|
2009-07-06 11:19:26 +02:00
|
|
|
ULONG newSize = base->used + length;
|
2008-02-06 14:47:08 +01:00
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
if (newSize > base->allocated)
|
2008-02-06 14:47:08 +01:00
|
|
|
{
|
2009-07-06 11:19:26 +02:00
|
|
|
newSize = FB_ALIGN(newSize, DEFAULT_SIZE);
|
|
|
|
|
|
|
|
#if (defined HAVE_MMAP || defined WIN_NT)
|
|
|
|
ISC_STATUS_ARRAY statusVector;
|
2010-07-16 09:20:55 +02:00
|
|
|
base = (Header*) ISC_remap_file(statusVector, &handle, newSize, true, &mutex);
|
2009-07-06 11:19:26 +02:00
|
|
|
if (!base)
|
|
|
|
{
|
|
|
|
status_exception::raise(statusVector);
|
|
|
|
}
|
|
|
|
base->allocated = handle.sh_mem_length_mapped;
|
2008-02-06 14:47:08 +01:00
|
|
|
#else
|
2009-07-06 11:19:26 +02:00
|
|
|
status_exception::raise(Arg::Gds(isc_montabexh));
|
2008-02-06 14:47:08 +01:00
|
|
|
#endif
|
2009-07-06 11:19:26 +02:00
|
|
|
}
|
2006-10-30 13:39:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-28 13:27:18 +01:00
|
|
|
void DatabaseSnapshot::SharedData::checkMutex(const TEXT* string, int state)
|
2006-10-30 13:39:08 +01:00
|
|
|
{
|
|
|
|
if (state)
|
|
|
|
{
|
|
|
|
TEXT msg[BUFFER_TINY];
|
|
|
|
|
|
|
|
sprintf(msg, "MONITOR: mutex %s error, status = %d", string, state);
|
2012-12-14 18:45:38 +01:00
|
|
|
fb_utils::logAndDie(msg);
|
2006-10-30 13:39:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-02 10:53:25 +02:00
|
|
|
void DatabaseSnapshot::SharedData::init(void* arg, sh_mem* shmemData, bool initialize)
|
2006-10-30 13:39:08 +01:00
|
|
|
{
|
2009-01-28 13:27:18 +01:00
|
|
|
SharedData* const shmem = (SharedData*) arg;
|
2006-10-30 13:39:08 +01:00
|
|
|
fb_assert(shmem);
|
|
|
|
|
|
|
|
#ifdef WIN_NT
|
2010-06-08 13:40:58 +02:00
|
|
|
checkMutex("init", ISC_mutex_init(&shmem->winMutex, shmemData->sh_mem_name));
|
|
|
|
shmem->mutex = &shmem->winMutex;
|
2006-10-30 13:39:08 +01:00
|
|
|
#endif
|
|
|
|
|
2010-06-08 13:40:58 +02:00
|
|
|
Header* const header = (Header*) shmemData->sh_mem_address;
|
|
|
|
|
2006-10-30 13:39:08 +01:00
|
|
|
if (!initialize)
|
2010-06-08 13:40:58 +02:00
|
|
|
{
|
|
|
|
#ifndef WIN_NT
|
|
|
|
checkMutex("map", ISC_map_mutex(shmemData, &header->mutex, &shmem->mutex));
|
|
|
|
#endif
|
2006-10-30 13:39:08 +01:00
|
|
|
return;
|
2010-06-08 13:40:58 +02:00
|
|
|
}
|
2006-10-30 13:39:08 +01:00
|
|
|
|
|
|
|
// Initialize the shared data header
|
2009-01-28 13:27:18 +01:00
|
|
|
header->version = MONITOR_VERSION;
|
2009-07-20 15:44:02 +02:00
|
|
|
header->used = alignOffset(sizeof(Header));
|
2008-12-11 12:58:50 +01:00
|
|
|
header->allocated = shmemData->sh_mem_length_mapped;
|
2006-10-30 13:39:08 +01:00
|
|
|
|
|
|
|
#ifndef WIN_NT
|
2010-06-08 13:40:58 +02:00
|
|
|
checkMutex("init", ISC_mutex_init(shmemData, &header->mutex, &shmem->mutex));
|
2006-10-30 13:39:08 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-20 15:44:02 +02:00
|
|
|
ULONG DatabaseSnapshot::SharedData::alignOffset(ULONG unaligned)
|
|
|
|
{
|
|
|
|
return Firebird::MEM_ALIGN(unaligned);
|
|
|
|
}
|
|
|
|
|
2006-10-30 13:39:08 +01:00
|
|
|
// DatabaseSnapshot class
|
|
|
|
|
2006-07-17 21:26:43 +02:00
|
|
|
|
2006-07-17 19:44:18 +02:00
|
|
|
DatabaseSnapshot* DatabaseSnapshot::create(thread_db* tdbb)
|
|
|
|
{
|
2006-07-18 08:00:52 +02:00
|
|
|
SET_TDBB(tdbb);
|
|
|
|
|
2007-12-03 16:46:39 +01:00
|
|
|
jrd_tra* transaction = tdbb->getTransaction();
|
2006-07-17 19:44:18 +02:00
|
|
|
fb_assert(transaction);
|
|
|
|
|
|
|
|
if (!transaction->tra_db_snapshot)
|
2006-10-30 13:39:08 +01:00
|
|
|
{
|
|
|
|
// Create a database snapshot and store it
|
|
|
|
// in the transaction block
|
2006-07-17 19:44:18 +02:00
|
|
|
MemoryPool& pool = *transaction->tra_pool;
|
2008-11-15 10:31:06 +01:00
|
|
|
transaction->tra_db_snapshot = FB_NEW(pool) DatabaseSnapshot(tdbb, pool);
|
2006-07-17 19:44:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return transaction->tra_db_snapshot;
|
|
|
|
}
|
|
|
|
|
2006-07-17 21:26:43 +02:00
|
|
|
|
2006-10-30 13:39:08 +01:00
|
|
|
int DatabaseSnapshot::blockingAst(void* ast_object)
|
2006-07-17 19:44:18 +02:00
|
|
|
{
|
2006-10-30 13:39:08 +01:00
|
|
|
Database* dbb = static_cast<Database*>(ast_object);
|
2006-07-17 19:44:18 +02:00
|
|
|
|
2008-03-12 17:53:57 +01:00
|
|
|
try
|
|
|
|
{
|
2008-12-11 12:58:50 +01:00
|
|
|
Lock* const lock = dbb->dbb_monitor_lock;
|
2012-12-27 14:26:31 +01:00
|
|
|
AstContextHolder tdbb(dbb, lock->lck_attachment);
|
2006-07-17 21:26:43 +02:00
|
|
|
|
2008-12-20 09:12:19 +01:00
|
|
|
ContextPoolHolder context(tdbb, dbb->dbb_permanent);
|
2006-07-17 19:44:18 +02:00
|
|
|
|
2008-03-12 17:53:57 +01:00
|
|
|
if (!(dbb->dbb_ast_flags & DBB_monitor_off))
|
|
|
|
{
|
2009-05-28 09:58:39 +02:00
|
|
|
// Write the data to the shared memory
|
2012-11-22 13:45:45 +01:00
|
|
|
try
|
2009-05-28 09:58:39 +02:00
|
|
|
{
|
2012-11-22 13:45:45 +01:00
|
|
|
dumpData(tdbb);
|
|
|
|
}
|
|
|
|
catch (const Exception& ex)
|
|
|
|
{
|
|
|
|
iscLogException("Cannot dump the monitoring data", ex);
|
2008-03-12 17:53:57 +01:00
|
|
|
}
|
2009-05-28 09:58:39 +02:00
|
|
|
|
2010-06-05 04:41:14 +02:00
|
|
|
// Release the lock, if feasible
|
|
|
|
if (!(dbb->dbb_flags & DBB_monitor_locking))
|
|
|
|
{
|
|
|
|
LCK_release(tdbb, lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark dbb as requesting a new lock
|
2009-05-28 09:58:39 +02:00
|
|
|
dbb->dbb_ast_flags |= DBB_monitor_off;
|
2007-12-10 07:31:04 +01:00
|
|
|
}
|
2007-07-16 17:26:04 +02:00
|
|
|
}
|
2008-12-20 09:12:19 +01:00
|
|
|
catch (const Exception&)
|
2008-03-12 17:53:57 +01:00
|
|
|
{} // no-op
|
2006-10-30 13:39:08 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2006-07-17 19:44:18 +02:00
|
|
|
|
|
|
|
|
2007-07-16 16:41:39 +02:00
|
|
|
DatabaseSnapshot::DatabaseSnapshot(thread_db* tdbb, MemoryPool& pool)
|
2007-09-14 17:13:19 +02:00
|
|
|
: snapshot(pool), idMap(pool), idCounter(0)
|
2006-10-30 13:39:08 +01:00
|
|
|
{
|
2008-12-11 12:58:50 +01:00
|
|
|
SET_TDBB(tdbb);
|
|
|
|
|
2008-07-09 10:40:31 +02:00
|
|
|
PAG_header(tdbb, true);
|
2008-05-06 11:06:04 +02:00
|
|
|
|
2008-03-26 15:04:04 +01:00
|
|
|
Database* const dbb = tdbb->getDatabase();
|
|
|
|
fb_assert(dbb);
|
|
|
|
|
|
|
|
const USHORT ods_version = ENCODE_ODS(dbb->dbb_ods_version, dbb->dbb_minor_original);
|
|
|
|
|
2006-10-30 13:39:08 +01:00
|
|
|
// Initialize record buffers
|
2007-12-10 07:31:04 +01:00
|
|
|
RecordBuffer* const dbb_buffer =
|
2008-03-26 15:04:04 +01:00
|
|
|
ods_version >= ODS_11_1 ? allocBuffer(tdbb, pool, rel_mon_database) : NULL;
|
2007-12-10 07:31:04 +01:00
|
|
|
RecordBuffer* const att_buffer =
|
2008-03-26 15:04:04 +01:00
|
|
|
ods_version >= ODS_11_1 ? allocBuffer(tdbb, pool, rel_mon_attachments) : NULL;
|
2007-12-10 07:31:04 +01:00
|
|
|
RecordBuffer* const tra_buffer =
|
2008-03-26 15:04:04 +01:00
|
|
|
ods_version >= ODS_11_1 ? allocBuffer(tdbb, pool, rel_mon_transactions) : NULL;
|
2007-12-10 07:31:04 +01:00
|
|
|
RecordBuffer* const stmt_buffer =
|
2008-03-26 15:04:04 +01:00
|
|
|
ods_version >= ODS_11_1 ? allocBuffer(tdbb, pool, rel_mon_statements) : NULL;
|
2007-12-10 07:31:04 +01:00
|
|
|
RecordBuffer* const call_buffer =
|
2008-03-26 15:04:04 +01:00
|
|
|
ods_version >= ODS_11_1 ? allocBuffer(tdbb, pool, rel_mon_calls) : NULL;
|
2007-12-10 07:31:04 +01:00
|
|
|
RecordBuffer* const io_stat_buffer =
|
2008-03-26 15:04:04 +01:00
|
|
|
ods_version >= ODS_11_1 ? allocBuffer(tdbb, pool, rel_mon_io_stats) : NULL;
|
2007-12-10 07:31:04 +01:00
|
|
|
RecordBuffer* const rec_stat_buffer =
|
2008-03-26 15:04:04 +01:00
|
|
|
ods_version >= ODS_11_1 ? allocBuffer(tdbb, pool, rel_mon_rec_stats) : NULL;
|
2008-02-20 14:13:22 +01:00
|
|
|
RecordBuffer* const ctx_var_buffer =
|
2008-03-26 15:04:04 +01:00
|
|
|
ods_version >= ODS_11_2 ? allocBuffer(tdbb, pool, rel_mon_ctx_vars) : NULL;
|
2008-05-06 10:46:39 +02:00
|
|
|
RecordBuffer* const mem_usage_buffer =
|
|
|
|
ods_version >= ODS_11_2 ? allocBuffer(tdbb, pool, rel_mon_mem_usage) : NULL;
|
2006-10-30 13:39:08 +01:00
|
|
|
|
2008-12-11 12:58:50 +01:00
|
|
|
// Release our own lock
|
|
|
|
LCK_release(tdbb, dbb->dbb_monitor_lock);
|
2010-05-06 14:07:34 +02:00
|
|
|
dbb->dbb_ast_flags &= ~DBB_monitor_off;
|
2007-07-16 16:41:39 +02:00
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
{ // scope for the RAII object
|
|
|
|
|
|
|
|
// Ensure we'll be dealing with a valid backup state inside the call below
|
|
|
|
BackupManager::StateReadGuard holder(tdbb);
|
|
|
|
|
|
|
|
// Dump our own data
|
|
|
|
dumpData(tdbb);
|
|
|
|
}
|
2006-10-30 13:39:08 +01:00
|
|
|
|
2008-12-11 12:58:50 +01:00
|
|
|
// Signal other processes to dump their data
|
|
|
|
Lock temp_lock, *lock = &temp_lock;
|
|
|
|
lock->lck_dbb = dbb;
|
|
|
|
lock->lck_length = sizeof(SLONG);
|
|
|
|
lock->lck_key.lck_long = 0;
|
|
|
|
lock->lck_type = LCK_monitor;
|
|
|
|
lock->lck_owner_handle = LCK_get_owner_handle(tdbb, lock->lck_type);
|
|
|
|
lock->lck_parent = dbb->dbb_lock;
|
2007-12-10 07:31:04 +01:00
|
|
|
|
2008-12-11 12:58:50 +01:00
|
|
|
if (LCK_lock(tdbb, lock, LCK_EX, LCK_WAIT))
|
|
|
|
LCK_release(tdbb, lock);
|
2007-12-10 07:31:04 +01:00
|
|
|
|
2008-12-11 12:58:50 +01:00
|
|
|
// Mark dbb as requesting a new lock
|
|
|
|
dbb->dbb_ast_flags |= DBB_monitor_off;
|
2007-07-16 16:41:39 +02:00
|
|
|
|
2008-12-11 12:58:50 +01:00
|
|
|
// Read the shared memory
|
|
|
|
ULONG dataSize = 0;
|
2009-07-06 11:19:26 +02:00
|
|
|
UCHAR* dataPtr = NULL;
|
|
|
|
|
|
|
|
{ // scope
|
|
|
|
fb_assert(dbb->dbb_monitoring_data);
|
|
|
|
DumpGuard guard(dbb->dbb_monitoring_data);
|
|
|
|
dataPtr = dbb->dbb_monitoring_data->read(pool, dataSize);
|
|
|
|
}
|
2007-12-10 07:31:04 +01:00
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
fb_assert(dataSize && dataPtr);
|
|
|
|
AutoPtr<UCHAR, ArrayDelete<UCHAR> > data(dataPtr);
|
|
|
|
|
|
|
|
Reader reader(dataSize, data);
|
2008-05-08 13:26:31 +02:00
|
|
|
|
2008-12-11 12:58:50 +01:00
|
|
|
const Attachment* const attachment = tdbb->getAttachment();
|
|
|
|
fb_assert(attachment);
|
2009-07-11 21:58:28 +02:00
|
|
|
|
|
|
|
string databaseName(dbb->dbb_database_name.c_str());
|
|
|
|
ISC_systemToUtf8(databaseName);
|
|
|
|
|
2008-12-11 12:58:50 +01:00
|
|
|
const string& userName = attachment->att_user->usr_user_name;
|
|
|
|
const bool locksmith = attachment->locksmith();
|
2006-07-17 19:44:18 +02:00
|
|
|
|
2007-07-16 17:26:04 +02:00
|
|
|
// Parse the dump
|
|
|
|
RecordBuffer* buffer = NULL;
|
|
|
|
Record* record = NULL;
|
2006-07-17 19:44:18 +02:00
|
|
|
|
2008-12-11 12:58:50 +01:00
|
|
|
bool dbb_processed = false, fields_processed = false;
|
|
|
|
bool dbb_allowed = false, att_allowed = false;
|
2009-07-06 11:19:26 +02:00
|
|
|
int attachment_charset = ttype_none;
|
2006-07-17 19:44:18 +02:00
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
DumpRecord dumpRecord;
|
|
|
|
while (reader.getRecord(dumpRecord))
|
2007-07-16 17:26:04 +02:00
|
|
|
{
|
2009-07-06 11:19:26 +02:00
|
|
|
const int rid = dumpRecord.getRelationId();
|
2006-10-30 13:39:08 +01:00
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
switch (rid)
|
|
|
|
{
|
|
|
|
case rel_mon_database:
|
|
|
|
buffer = dbb_buffer;
|
|
|
|
break;
|
|
|
|
case rel_mon_attachments:
|
|
|
|
buffer = att_buffer;
|
|
|
|
break;
|
|
|
|
case rel_mon_transactions:
|
|
|
|
buffer = tra_buffer;
|
|
|
|
break;
|
|
|
|
case rel_mon_statements:
|
|
|
|
buffer = stmt_buffer;
|
|
|
|
break;
|
|
|
|
case rel_mon_calls:
|
|
|
|
buffer = call_buffer;
|
|
|
|
break;
|
|
|
|
case rel_mon_io_stats:
|
|
|
|
buffer = io_stat_buffer;
|
|
|
|
break;
|
|
|
|
case rel_mon_rec_stats:
|
|
|
|
buffer = rec_stat_buffer;
|
|
|
|
break;
|
|
|
|
case rel_mon_ctx_vars:
|
|
|
|
buffer = ctx_var_buffer;
|
|
|
|
break;
|
|
|
|
case rel_mon_mem_usage:
|
|
|
|
buffer = mem_usage_buffer;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fb_assert(false);
|
|
|
|
}
|
2007-07-16 17:26:04 +02:00
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
record = buffer->getTempRecord();
|
|
|
|
clearRecord(record);
|
2007-07-16 17:26:04 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-07-06 11:19:26 +02:00
|
|
|
record = NULL;
|
|
|
|
}
|
2006-10-30 13:39:08 +01:00
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
DumpField dumpField;
|
|
|
|
while (dumpRecord.getField(dumpField))
|
|
|
|
{
|
|
|
|
const USHORT fid = dumpField.id;
|
|
|
|
const size_t length = dumpField.length;
|
|
|
|
const char* source = (const char*) dumpField.data;
|
|
|
|
|
|
|
|
bool set_charset = false;
|
2011-06-02 15:48:11 +02:00
|
|
|
int charset = attachment_charset;
|
2006-10-30 13:39:08 +01:00
|
|
|
|
2008-12-29 18:32:37 +01:00
|
|
|
// special case for MON$DATABASE
|
|
|
|
if (rid == rel_mon_database)
|
2007-07-16 17:26:04 +02:00
|
|
|
{
|
|
|
|
if (fid == f_mon_db_name)
|
2006-10-30 13:39:08 +01:00
|
|
|
{
|
2011-06-02 15:48:11 +02:00
|
|
|
charset = ttype_metadata; // already in Unicode
|
2008-12-11 12:58:50 +01:00
|
|
|
dbb_allowed = !databaseName.compare(source, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (record && dbb_allowed && !dbb_processed)
|
|
|
|
{
|
2011-06-02 15:48:11 +02:00
|
|
|
putField(tdbb, record, dumpField, charset);
|
2008-12-11 12:58:50 +01:00
|
|
|
fields_processed = true;
|
|
|
|
}
|
2008-12-29 18:32:37 +01:00
|
|
|
|
|
|
|
att_allowed = (dbb_allowed && !dbb_processed);
|
2008-12-11 12:58:50 +01:00
|
|
|
}
|
2008-12-29 18:32:37 +01:00
|
|
|
// special case for MON$ATTACHMENTS
|
|
|
|
else if (rid == rel_mon_attachments)
|
2008-12-11 12:58:50 +01:00
|
|
|
{
|
|
|
|
if (fid == f_mon_att_user)
|
|
|
|
{
|
2009-07-11 21:58:28 +02:00
|
|
|
attachment_charset = ttype_none;
|
2011-06-02 15:48:11 +02:00
|
|
|
charset = ttype_metadata; // already in Unicode
|
2008-12-13 10:19:55 +01:00
|
|
|
att_allowed = locksmith || !userName.compare(source, length);
|
2006-10-30 13:39:08 +01:00
|
|
|
}
|
2011-07-22 08:52:47 +02:00
|
|
|
else if (fid == f_mon_att_name || fid == f_mon_att_role || fid == f_mon_att_remote_process)
|
2011-06-02 15:48:11 +02:00
|
|
|
{
|
|
|
|
charset = ttype_metadata; // already in Unicode
|
|
|
|
}
|
2009-07-06 11:19:26 +02:00
|
|
|
else if (fid == f_mon_att_charset_id)
|
|
|
|
{
|
|
|
|
set_charset = true;
|
|
|
|
}
|
2007-07-16 16:41:39 +02:00
|
|
|
|
2008-12-11 12:58:50 +01:00
|
|
|
if (record && dbb_allowed && att_allowed)
|
2006-10-30 13:39:08 +01:00
|
|
|
{
|
2011-06-02 15:48:11 +02:00
|
|
|
putField(tdbb, record, dumpField, set_charset ? attachment_charset : charset, set_charset);
|
2006-10-30 13:39:08 +01:00
|
|
|
fields_processed = true;
|
2008-12-11 12:58:50 +01:00
|
|
|
dbb_processed = true;
|
2006-10-30 13:39:08 +01:00
|
|
|
}
|
2006-07-17 19:44:18 +02:00
|
|
|
}
|
2008-12-29 18:32:37 +01:00
|
|
|
// generic logic that covers all other relations
|
|
|
|
else if (record && dbb_allowed && att_allowed)
|
2007-07-16 17:26:04 +02:00
|
|
|
{
|
2011-06-02 15:48:11 +02:00
|
|
|
if (rid == rel_mon_calls && fid == f_mon_call_name)
|
|
|
|
{
|
|
|
|
charset = ttype_metadata; // already in Unicode
|
|
|
|
}
|
|
|
|
|
|
|
|
putField(tdbb, record, dumpField, charset);
|
2007-07-16 17:26:04 +02:00
|
|
|
fields_processed = true;
|
2008-12-11 12:58:50 +01:00
|
|
|
dbb_processed = true;
|
2007-07-16 17:26:04 +02:00
|
|
|
}
|
2006-10-30 13:39:08 +01:00
|
|
|
}
|
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
if (fields_processed)
|
|
|
|
{
|
|
|
|
buffer->store(record);
|
2009-07-07 07:17:55 +02:00
|
|
|
fields_processed = false;
|
2009-07-06 11:19:26 +02:00
|
|
|
}
|
2007-07-16 17:26:04 +02:00
|
|
|
}
|
2006-07-17 19:44:18 +02:00
|
|
|
}
|
|
|
|
|
2006-07-17 21:26:43 +02:00
|
|
|
|
2006-07-17 19:44:18 +02:00
|
|
|
DatabaseSnapshot::~DatabaseSnapshot()
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < snapshot.getCount(); i++)
|
|
|
|
{
|
|
|
|
delete snapshot[i].data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-17 21:26:43 +02:00
|
|
|
|
2011-02-15 09:38:32 +01:00
|
|
|
RecordBuffer* DatabaseSnapshot::getData(const jrd_rel* relation) const
|
2006-07-17 19:44:18 +02:00
|
|
|
{
|
2011-02-15 09:38:32 +01:00
|
|
|
fb_assert(relation);
|
|
|
|
|
2006-07-17 19:44:18 +02:00
|
|
|
for (size_t i = 0; i < snapshot.getCount(); i++)
|
|
|
|
{
|
2011-02-15 09:38:32 +01:00
|
|
|
if (snapshot[i].rel_id == relation->rel_id)
|
|
|
|
return snapshot[i].data;
|
2006-07-17 19:44:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-07-17 21:26:43 +02:00
|
|
|
|
2008-12-13 10:19:55 +01:00
|
|
|
RecordBuffer* DatabaseSnapshot::allocBuffer(thread_db* tdbb, MemoryPool& pool, int rel_id)
|
2006-10-30 13:39:08 +01:00
|
|
|
{
|
2011-02-14 12:10:58 +01:00
|
|
|
jrd_rel* const relation = MET_lookup_relation_id(tdbb, rel_id, false);
|
2006-10-30 13:39:08 +01:00
|
|
|
fb_assert(relation);
|
|
|
|
MET_scan_relation(tdbb, relation);
|
|
|
|
fb_assert(relation->isVirtual());
|
2011-02-14 12:10:58 +01:00
|
|
|
|
|
|
|
const Format* const format = MET_current(tdbb, relation);
|
2006-10-30 13:39:08 +01:00
|
|
|
fb_assert(format);
|
|
|
|
|
2011-02-14 12:10:58 +01:00
|
|
|
RecordBuffer* const buffer = FB_NEW(pool) RecordBuffer(pool, format);
|
2011-02-15 09:38:32 +01:00
|
|
|
RelationData data = {relation->rel_id, buffer};
|
2006-10-30 13:39:08 +01:00
|
|
|
snapshot.add(data);
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-17 21:26:43 +02:00
|
|
|
void DatabaseSnapshot::clearRecord(Record* record)
|
|
|
|
{
|
2008-03-26 15:04:04 +01:00
|
|
|
fb_assert(record);
|
|
|
|
|
2006-07-17 21:26:43 +02:00
|
|
|
// Initialize all fields to NULLs
|
|
|
|
memset(record->rec_data, 0, record->rec_length);
|
2009-06-10 14:48:05 +02:00
|
|
|
const size_t null_bytes = (record->rec_format->fmt_count + 7u) >> 3;
|
2006-07-17 21:26:43 +02:00
|
|
|
memset(record->rec_data, 0xFF, null_bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
void DatabaseSnapshot::putField(thread_db* tdbb, Record* record, const DumpField& field,
|
|
|
|
int& charset, bool set_charset)
|
2006-07-17 19:44:18 +02:00
|
|
|
{
|
|
|
|
fb_assert(record);
|
|
|
|
|
|
|
|
const Format* const format = record->rec_format;
|
2011-02-14 12:10:58 +01:00
|
|
|
fb_assert(format);
|
|
|
|
|
|
|
|
dsc to_desc;
|
|
|
|
|
|
|
|
if (field.id < format->fmt_count)
|
|
|
|
{
|
|
|
|
to_desc = format->fmt_desc[field.id];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (to_desc.isUnknown())
|
|
|
|
return;
|
2006-07-17 19:44:18 +02:00
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
to_desc.dsc_address += (IPTR) record->rec_data;
|
2006-07-17 19:44:18 +02:00
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
if (field.type == VALUE_GLOBAL_ID)
|
2007-09-14 17:13:19 +02:00
|
|
|
{
|
|
|
|
// special case: translate 64-bit global ID into 32-bit local ID
|
2009-07-06 11:19:26 +02:00
|
|
|
fb_assert(field.length == sizeof(SINT64));
|
|
|
|
SINT64 global_id;
|
|
|
|
memcpy(&global_id, field.data, field.length);
|
|
|
|
SLONG local_id;
|
2007-09-14 17:13:19 +02:00
|
|
|
if (!idMap.get(global_id, local_id))
|
|
|
|
{
|
|
|
|
local_id = ++idCounter;
|
|
|
|
idMap.put(global_id, local_id);
|
|
|
|
}
|
2009-07-06 11:19:26 +02:00
|
|
|
dsc from_desc;
|
|
|
|
from_desc.makeLong(0, &local_id);
|
|
|
|
MOV_move(tdbb, &from_desc, &to_desc);
|
2007-09-14 17:13:19 +02:00
|
|
|
}
|
2009-07-06 11:19:26 +02:00
|
|
|
else if (field.type == VALUE_INTEGER)
|
2009-01-20 09:33:59 +01:00
|
|
|
{
|
2009-07-06 11:19:26 +02:00
|
|
|
fb_assert(field.length == sizeof(SINT64));
|
|
|
|
SINT64 value;
|
|
|
|
memcpy(&value, field.data, field.length);
|
|
|
|
dsc from_desc;
|
|
|
|
from_desc.makeInt64(0, &value);
|
|
|
|
MOV_move(tdbb, &from_desc, &to_desc);
|
|
|
|
|
|
|
|
if (set_charset)
|
2006-07-17 19:44:18 +02:00
|
|
|
{
|
2009-07-06 11:19:26 +02:00
|
|
|
charset = (int) value;
|
2006-07-17 19:44:18 +02:00
|
|
|
}
|
|
|
|
}
|
2009-07-06 11:19:26 +02:00
|
|
|
else if (field.type == VALUE_TIMESTAMP)
|
2008-05-06 10:46:39 +02:00
|
|
|
{
|
2009-07-06 11:19:26 +02:00
|
|
|
fb_assert(field.length == sizeof(ISC_TIMESTAMP));
|
|
|
|
ISC_TIMESTAMP value;
|
|
|
|
memcpy(&value, field.data, field.length);
|
|
|
|
dsc from_desc;
|
|
|
|
from_desc.makeTimestamp(&value);
|
|
|
|
MOV_move(tdbb, &from_desc, &to_desc);
|
|
|
|
}
|
|
|
|
else if (field.type == VALUE_STRING)
|
|
|
|
{
|
|
|
|
dsc from_desc;
|
2009-08-27 18:17:35 +02:00
|
|
|
MoveBuffer buffer;
|
|
|
|
|
|
|
|
if (charset == CS_NONE && to_desc.getCharSet() == CS_METADATA)
|
|
|
|
{
|
2009-08-28 07:04:43 +02:00
|
|
|
// ASF: If an attachment using NONE charset has a string using non-ASCII characters,
|
|
|
|
// nobody will be able to select them in a system field. So we change these characters to
|
2009-08-27 18:17:35 +02:00
|
|
|
// question marks here - CORE-2602.
|
|
|
|
|
|
|
|
UCHAR* p = buffer.getBuffer(field.length);
|
|
|
|
const UCHAR* s = (const UCHAR*) field.data;
|
|
|
|
|
|
|
|
for (const UCHAR* end = buffer.end(); p < end; ++p, ++s)
|
|
|
|
*p = (*s > 0x7F ? '?' : *s);
|
|
|
|
|
|
|
|
from_desc.makeText(field.length, CS_ASCII, buffer.begin());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
from_desc.makeText(field.length, charset, (UCHAR*) field.data);
|
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
MOV_move(tdbb, &from_desc, &to_desc);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fb_assert(false);
|
2006-10-30 13:39:08 +01:00
|
|
|
}
|
|
|
|
|
2009-09-24 04:11:10 +02:00
|
|
|
// hvlad: detach just created temporary blob from request to bound its
|
2009-09-16 23:27:12 +02:00
|
|
|
// lifetime to transaction. This is necessary as this blob belongs to
|
|
|
|
// the MON$ table and must be accessible until transaction ends.
|
2009-09-17 17:55:18 +02:00
|
|
|
if (to_desc.isBlob())
|
2009-09-16 23:27:12 +02:00
|
|
|
{
|
2009-09-17 13:10:55 +02:00
|
|
|
bid* blob_id = reinterpret_cast<bid*>(to_desc.dsc_address);
|
|
|
|
jrd_tra* tran = tdbb->getTransaction();
|
2009-09-16 23:27:12 +02:00
|
|
|
|
2009-09-17 13:10:55 +02:00
|
|
|
const bool traFound = tran->tra_blobs->locate(blob_id->bid_temp_id());
|
|
|
|
fb_assert(traFound);
|
2009-09-16 23:27:12 +02:00
|
|
|
|
2009-09-17 13:10:55 +02:00
|
|
|
BlobIndex& blobIdx = tran->tra_blobs->current();
|
2009-09-16 23:27:12 +02:00
|
|
|
fb_assert(!blobIdx.bli_materialized);
|
|
|
|
|
|
|
|
if (blobIdx.bli_request)
|
|
|
|
{
|
2009-09-17 13:10:55 +02:00
|
|
|
const bool reqFound = blobIdx.bli_request->req_blobs.locate(blobIdx.bli_temp_id);
|
|
|
|
fb_assert(reqFound);
|
2009-09-24 04:11:10 +02:00
|
|
|
|
2009-09-16 23:27:12 +02:00
|
|
|
blobIdx.bli_request->req_blobs.fastRemove();
|
|
|
|
blobIdx.bli_request = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
CLEAR_NULL(record, field.id);
|
2006-10-30 13:39:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-11 12:58:50 +01:00
|
|
|
void DatabaseSnapshot::dumpData(thread_db* tdbb)
|
2006-10-30 13:39:08 +01:00
|
|
|
{
|
|
|
|
fb_assert(tdbb);
|
2008-12-11 12:58:50 +01:00
|
|
|
|
2007-12-10 07:31:04 +01:00
|
|
|
Database* const dbb = tdbb->getDatabase();
|
2006-10-30 13:39:08 +01:00
|
|
|
fb_assert(dbb);
|
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
if (!dbb->dbb_monitoring_data)
|
|
|
|
{
|
|
|
|
dbb->dbb_monitoring_data = FB_NEW(*dbb->dbb_permanent) SharedData(dbb);
|
|
|
|
}
|
|
|
|
|
|
|
|
DumpGuard guard(dbb->dbb_monitoring_data);
|
|
|
|
dbb->dbb_monitoring_data->cleanup();
|
|
|
|
|
|
|
|
Writer writer(dbb->dbb_monitoring_data);
|
2006-10-30 13:39:08 +01:00
|
|
|
|
|
|
|
// Database information
|
|
|
|
|
2008-12-11 12:58:50 +01:00
|
|
|
putDatabase(dbb, writer, fb_utils::genUniqueId());
|
2006-10-30 13:39:08 +01:00
|
|
|
|
2007-12-10 07:31:04 +01:00
|
|
|
// Attachment information
|
2007-07-16 16:41:39 +02:00
|
|
|
|
2008-12-20 09:12:19 +01:00
|
|
|
for (Attachment* attachment = dbb->dbb_attachments; attachment; attachment = attachment->att_next)
|
2007-07-16 16:41:39 +02:00
|
|
|
{
|
2009-05-29 16:10:18 +02:00
|
|
|
if (!putAttachment(attachment, writer, fb_utils::genUniqueId()))
|
|
|
|
continue;
|
|
|
|
|
2008-12-13 10:19:55 +01:00
|
|
|
putContextVars(attachment->att_context_vars, writer, attachment->att_attachment_id, true);
|
2007-07-16 16:41:39 +02:00
|
|
|
|
2008-12-11 12:58:50 +01:00
|
|
|
jrd_tra* transaction = NULL;
|
|
|
|
jrd_req* request = NULL;
|
2008-04-19 11:42:01 +02:00
|
|
|
|
2008-12-11 12:58:50 +01:00
|
|
|
// Transaction information
|
2007-07-16 16:41:39 +02:00
|
|
|
|
2008-12-11 12:58:50 +01:00
|
|
|
for (transaction = attachment->att_transactions;
|
|
|
|
transaction; transaction = transaction->tra_next)
|
|
|
|
{
|
|
|
|
putTransaction(transaction, writer, fb_utils::genUniqueId());
|
2008-12-13 10:19:55 +01:00
|
|
|
putContextVars(transaction->tra_context_vars, writer, transaction->tra_number, false);
|
2008-12-11 12:58:50 +01:00
|
|
|
}
|
2006-10-30 13:39:08 +01:00
|
|
|
|
2008-12-11 12:58:50 +01:00
|
|
|
// Call stack information
|
2007-03-05 08:50:23 +01:00
|
|
|
|
2008-12-11 12:58:50 +01:00
|
|
|
for (transaction = attachment->att_transactions;
|
|
|
|
transaction; transaction = transaction->tra_next)
|
|
|
|
{
|
2012-03-14 16:24:12 +01:00
|
|
|
for (request = transaction->tra_requests;
|
|
|
|
request && (request->req_flags & req_active);
|
|
|
|
request = request->req_caller)
|
2007-03-05 08:50:23 +01:00
|
|
|
{
|
2008-12-11 12:58:50 +01:00
|
|
|
request->adjustCallerStats();
|
2008-11-06 17:04:20 +01:00
|
|
|
|
2008-12-14 09:55:39 +01:00
|
|
|
if (!(request->req_flags & (req_internal | req_sys_trigger)) && request->req_caller)
|
2008-11-06 17:04:20 +01:00
|
|
|
{
|
2008-12-11 12:58:50 +01:00
|
|
|
putCall(request, writer, fb_utils::genUniqueId());
|
2008-11-06 17:04:20 +01:00
|
|
|
}
|
|
|
|
}
|
2007-03-05 08:50:23 +01:00
|
|
|
}
|
2006-10-30 13:39:08 +01:00
|
|
|
|
2008-12-11 12:58:50 +01:00
|
|
|
// Request information
|
|
|
|
|
|
|
|
for (request = attachment->att_requests; request; request = request->req_request)
|
2006-10-30 13:39:08 +01:00
|
|
|
{
|
2008-12-11 12:58:50 +01:00
|
|
|
if (!(request->req_flags & (req_internal | req_sys_trigger)))
|
2007-12-10 07:31:04 +01:00
|
|
|
{
|
2008-12-11 12:58:50 +01:00
|
|
|
putRequest(request, writer, fb_utils::genUniqueId());
|
2007-12-10 07:31:04 +01:00
|
|
|
}
|
2006-10-30 13:39:08 +01:00
|
|
|
}
|
2008-12-11 12:58:50 +01:00
|
|
|
}
|
|
|
|
}
|
2007-12-10 07:31:04 +01:00
|
|
|
|
2006-10-30 13:39:08 +01:00
|
|
|
|
2008-12-11 12:58:50 +01:00
|
|
|
SINT64 DatabaseSnapshot::getGlobalId(int value)
|
|
|
|
{
|
|
|
|
return ((SINT64) getpid() << BITS_PER_LONG) + value;
|
2006-10-30 13:39:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
void DatabaseSnapshot::putDatabase(const Database* database, Writer& writer, int stat_id)
|
2006-07-17 19:44:18 +02:00
|
|
|
{
|
2006-10-30 13:39:08 +01:00
|
|
|
fb_assert(database);
|
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
DumpRecord record(rel_mon_database);
|
2006-07-17 19:44:18 +02:00
|
|
|
|
2009-07-11 21:58:28 +02:00
|
|
|
PathName databaseName(*getDefaultMemoryPool(), database->dbb_database_name);
|
|
|
|
ISC_systemToUtf8(databaseName);
|
|
|
|
|
2008-12-11 12:58:50 +01:00
|
|
|
// database name or alias (MUST BE ALWAYS THE FIRST ITEM PASSED!)
|
2009-07-11 21:58:28 +02:00
|
|
|
record.storeString(f_mon_db_name, databaseName);
|
2006-07-17 19:44:18 +02:00
|
|
|
// page size
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_db_page_size, database->dbb_page_size);
|
2006-07-17 19:44:18 +02:00
|
|
|
// major ODS version
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_db_ods_major, database->dbb_ods_version);
|
2006-07-17 19:44:18 +02:00
|
|
|
// minor ODS version
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_db_ods_minor, database->dbb_minor_version);
|
2006-07-17 19:44:18 +02:00
|
|
|
// oldest interesting transaction
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_db_oit, database->dbb_oldest_transaction);
|
2006-07-17 19:44:18 +02:00
|
|
|
// oldest active transaction
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_db_oat, database->dbb_oldest_active);
|
2006-07-17 19:44:18 +02:00
|
|
|
// oldest snapshot transaction
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_db_ost, database->dbb_oldest_snapshot);
|
2006-07-17 19:44:18 +02:00
|
|
|
// next transaction
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_db_nt, database->dbb_next_transaction);
|
2006-07-17 19:44:18 +02:00
|
|
|
// number of page buffers
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_db_page_bufs, database->dbb_bcb->bcb_count);
|
2008-04-19 11:42:01 +02:00
|
|
|
|
|
|
|
int temp;
|
|
|
|
|
2006-07-17 19:44:18 +02:00
|
|
|
// SQL dialect
|
2006-10-30 13:39:08 +01:00
|
|
|
temp = (database->dbb_flags & DBB_DB_SQL_dialect_3) ? 3 : 1;
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_db_dialect, temp);
|
2008-12-05 02:20:14 +01:00
|
|
|
|
2006-07-17 19:44:18 +02:00
|
|
|
// shutdown mode
|
2006-10-30 13:39:08 +01:00
|
|
|
if (database->dbb_ast_flags & DBB_shutdown_full)
|
2009-07-06 11:19:26 +02:00
|
|
|
{
|
2006-10-30 13:39:08 +01:00
|
|
|
temp = shut_mode_full;
|
2009-07-06 11:19:26 +02:00
|
|
|
}
|
2006-10-30 13:39:08 +01:00
|
|
|
else if (database->dbb_ast_flags & DBB_shutdown_single)
|
2009-07-06 11:19:26 +02:00
|
|
|
{
|
2006-10-30 13:39:08 +01:00
|
|
|
temp = shut_mode_single;
|
2009-07-06 11:19:26 +02:00
|
|
|
}
|
2006-10-30 13:39:08 +01:00
|
|
|
else if (database->dbb_ast_flags & DBB_shutdown)
|
2009-07-06 11:19:26 +02:00
|
|
|
{
|
2006-10-30 13:39:08 +01:00
|
|
|
temp = shut_mode_multi;
|
2009-07-06 11:19:26 +02:00
|
|
|
}
|
2006-07-17 19:44:18 +02:00
|
|
|
else
|
2009-07-06 11:19:26 +02:00
|
|
|
{
|
2006-10-30 13:39:08 +01:00
|
|
|
temp = shut_mode_online;
|
2009-07-06 11:19:26 +02:00
|
|
|
}
|
|
|
|
record.storeInteger(f_mon_db_shut_mode, temp);
|
2007-09-15 04:37:04 +02:00
|
|
|
|
2006-07-17 19:44:18 +02:00
|
|
|
// sweep interval
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_db_sweep_int, database->dbb_sweep_interval);
|
2006-07-17 19:44:18 +02:00
|
|
|
// read only flag
|
2006-10-30 13:39:08 +01:00
|
|
|
temp = (database->dbb_flags & DBB_read_only) ? 1 : 0;
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_db_read_only, temp);
|
2006-07-17 19:44:18 +02:00
|
|
|
// forced writes flag
|
2006-10-30 13:39:08 +01:00
|
|
|
temp = (database->dbb_flags & DBB_force_write) ? 1 : 0;
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_db_forced_writes, temp);
|
2006-07-17 19:44:18 +02:00
|
|
|
// reserve space flag
|
2006-10-30 13:39:08 +01:00
|
|
|
temp = (database->dbb_flags & DBB_no_reserve) ? 0 : 1;
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_db_res_space, temp);
|
2006-07-17 19:44:18 +02:00
|
|
|
// creation date
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeTimestamp(f_mon_db_created, database->dbb_creation_date);
|
2006-07-17 19:44:18 +02:00
|
|
|
// database size
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_db_pages, PageSpace::actAlloc(database));
|
2007-09-15 04:37:04 +02:00
|
|
|
|
2007-09-14 17:39:53 +02:00
|
|
|
// database state
|
2009-07-06 11:19:26 +02:00
|
|
|
switch (database->dbb_backup_manager->getState())
|
|
|
|
{
|
|
|
|
case nbak_state_normal:
|
|
|
|
temp = backup_state_normal;
|
|
|
|
break;
|
|
|
|
case nbak_state_stalled:
|
|
|
|
temp = backup_state_stalled;
|
|
|
|
break;
|
|
|
|
case nbak_state_merge:
|
|
|
|
temp = backup_state_merge;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
temp = backup_state_unknown;
|
2007-09-14 17:39:53 +02:00
|
|
|
}
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_db_backup_state, temp);
|
|
|
|
|
2007-09-14 17:59:05 +02:00
|
|
|
// statistics
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeGlobalId(f_mon_db_stat_id, getGlobalId(stat_id));
|
|
|
|
writer.putRecord(record);
|
2009-08-19 11:35:03 +02:00
|
|
|
|
2009-08-20 03:32:24 +02:00
|
|
|
if (SHARED_DBB)
|
2009-08-19 11:35:03 +02:00
|
|
|
{
|
2012-03-15 10:28:18 +01:00
|
|
|
putStatistics(database->dbb_stats, writer, stat_id, stat_database);
|
2009-08-19 11:35:03 +02:00
|
|
|
putMemoryUsage(database->dbb_memory_stats, writer, stat_id, stat_database);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-15 10:28:18 +01:00
|
|
|
RuntimeStatistics zero_rt_stats;
|
|
|
|
MemoryStats zero_mem_stats;
|
|
|
|
putStatistics(zero_rt_stats, writer, stat_id, stat_database);
|
|
|
|
putMemoryUsage(zero_mem_stats, writer, stat_id, stat_database);
|
2009-08-19 11:35:03 +02:00
|
|
|
}
|
2006-07-17 19:44:18 +02:00
|
|
|
}
|
|
|
|
|
2006-07-17 21:26:43 +02:00
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
bool DatabaseSnapshot::putAttachment(const Attachment* attachment, Writer& writer, int stat_id)
|
2006-07-17 19:44:18 +02:00
|
|
|
{
|
2006-10-30 13:39:08 +01:00
|
|
|
fb_assert(attachment);
|
2006-07-17 21:26:43 +02:00
|
|
|
|
2009-05-29 16:10:18 +02:00
|
|
|
if (!attachment->att_user)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
DumpRecord record(rel_mon_attachments);
|
2006-07-17 19:44:18 +02:00
|
|
|
|
2007-03-05 08:50:23 +01:00
|
|
|
int temp = mon_state_idle;
|
2006-07-19 07:30:21 +02:00
|
|
|
|
2008-04-19 11:42:01 +02:00
|
|
|
for (const jrd_tra* transaction_itr = attachment->att_transactions;
|
2006-09-01 12:51:57 +02:00
|
|
|
transaction_itr; transaction_itr = transaction_itr->tra_next)
|
2006-07-19 07:30:21 +02:00
|
|
|
{
|
2006-09-01 12:51:57 +02:00
|
|
|
if (transaction_itr->tra_requests)
|
|
|
|
{
|
2007-03-05 08:50:23 +01:00
|
|
|
temp = mon_state_active;
|
2006-09-01 12:51:57 +02:00
|
|
|
break;
|
|
|
|
}
|
2006-07-19 07:30:21 +02:00
|
|
|
}
|
|
|
|
|
2009-07-11 21:58:28 +02:00
|
|
|
PathName attName(*getDefaultMemoryPool(), attachment->att_filename);
|
|
|
|
ISC_systemToUtf8(attName);
|
|
|
|
|
2008-12-11 12:58:50 +01:00
|
|
|
// user (MUST BE ALWAYS THE FIRST ITEM PASSED!)
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeString(f_mon_att_user, attachment->att_user->usr_user_name);
|
2006-07-17 19:44:18 +02:00
|
|
|
// attachment id
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_att_id, attachment->att_attachment_id);
|
2006-07-17 19:44:18 +02:00
|
|
|
// process id
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_att_server_pid, getpid());
|
2006-07-19 07:30:21 +02:00
|
|
|
// state
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_att_state, temp);
|
2006-07-17 19:44:18 +02:00
|
|
|
// attachment name
|
2009-07-11 21:58:28 +02:00
|
|
|
record.storeString(f_mon_att_name, attName);
|
2006-07-17 19:44:18 +02:00
|
|
|
// role
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeString(f_mon_att_role, attachment->att_user->usr_sql_role_name);
|
2006-07-17 19:44:18 +02:00
|
|
|
// remote protocol
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeString(f_mon_att_remote_proto, attachment->att_network_protocol);
|
2006-07-17 19:44:18 +02:00
|
|
|
// remote address
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeString(f_mon_att_remote_addr, attachment->att_remote_address);
|
2006-09-14 15:47:31 +02:00
|
|
|
// remote process id
|
2009-07-06 11:19:26 +02:00
|
|
|
if (attachment->att_remote_pid)
|
|
|
|
{
|
|
|
|
record.storeInteger(f_mon_att_remote_pid, attachment->att_remote_pid);
|
|
|
|
}
|
2007-05-16 09:54:33 +02:00
|
|
|
// remote process name
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeString(f_mon_att_remote_process, attachment->att_remote_process);
|
2006-07-17 19:44:18 +02:00
|
|
|
// charset
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_att_charset_id, attachment->att_charset);
|
2006-07-17 19:44:18 +02:00
|
|
|
// timestamp
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeTimestamp(f_mon_att_timestamp, attachment->att_timestamp);
|
2006-07-17 19:44:18 +02:00
|
|
|
// garbage collection flag
|
2006-10-30 13:39:08 +01:00
|
|
|
temp = (attachment->att_flags & ATT_no_cleanup) ? 0 : 1;
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_att_gc, temp);
|
|
|
|
|
2007-09-14 17:13:19 +02:00
|
|
|
// statistics
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeGlobalId(f_mon_att_stat_id, getGlobalId(stat_id));
|
|
|
|
writer.putRecord(record);
|
2009-08-19 11:35:03 +02:00
|
|
|
|
2009-08-20 03:32:24 +02:00
|
|
|
if (SHARED_DBB)
|
2009-08-19 11:35:03 +02:00
|
|
|
{
|
2012-03-15 10:28:18 +01:00
|
|
|
putStatistics(attachment->att_stats, writer, stat_id, stat_attachment);
|
2009-08-19 11:35:03 +02:00
|
|
|
putMemoryUsage(attachment->att_memory_stats, writer, stat_id, stat_attachment);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-15 10:28:18 +01:00
|
|
|
putStatistics(attachment->att_database->dbb_stats, writer, stat_id, stat_attachment);
|
2009-08-19 11:35:03 +02:00
|
|
|
putMemoryUsage(attachment->att_database->dbb_memory_stats, writer, stat_id, stat_attachment);
|
|
|
|
}
|
2009-05-29 16:10:18 +02:00
|
|
|
|
|
|
|
return true;
|
2006-07-17 19:44:18 +02:00
|
|
|
}
|
|
|
|
|
2006-07-17 21:26:43 +02:00
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
void DatabaseSnapshot::putTransaction(const jrd_tra* transaction, Writer& writer, int stat_id)
|
2006-07-17 19:44:18 +02:00
|
|
|
{
|
2007-09-14 17:13:19 +02:00
|
|
|
fb_assert(transaction);
|
2006-07-17 19:44:18 +02:00
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
DumpRecord record(rel_mon_transactions);
|
2006-07-17 19:44:18 +02:00
|
|
|
|
2006-10-30 13:39:08 +01:00
|
|
|
int temp;
|
2006-07-17 19:44:18 +02:00
|
|
|
|
|
|
|
// transaction id
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_tra_id, transaction->tra_number);
|
2006-07-17 19:44:18 +02:00
|
|
|
// attachment id
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_tra_att_id, transaction->tra_attachment->att_attachment_id);
|
2006-07-19 07:30:21 +02:00
|
|
|
// state
|
2007-09-14 17:13:19 +02:00
|
|
|
temp = transaction->tra_requests ? mon_state_active : mon_state_idle;
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_tra_state, temp);
|
2006-07-17 19:44:18 +02:00
|
|
|
// timestamp
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeTimestamp(f_mon_tra_timestamp, transaction->tra_timestamp);
|
2006-07-17 19:44:18 +02:00
|
|
|
// top transaction
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_tra_top, transaction->tra_top);
|
2006-07-17 19:44:18 +02:00
|
|
|
// oldest transaction
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_tra_oit, transaction->tra_oldest);
|
2006-07-17 19:44:18 +02:00
|
|
|
// oldest active transaction
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_tra_oat, transaction->tra_oldest_active);
|
2006-07-17 19:44:18 +02:00
|
|
|
// isolation mode
|
2007-09-14 17:13:19 +02:00
|
|
|
if (transaction->tra_flags & TRA_degree3)
|
2009-07-06 11:19:26 +02:00
|
|
|
{
|
2006-10-30 13:39:08 +01:00
|
|
|
temp = iso_mode_consistency;
|
2009-07-06 11:19:26 +02:00
|
|
|
}
|
2007-09-14 17:13:19 +02:00
|
|
|
else if (transaction->tra_flags & TRA_read_committed)
|
2008-04-19 11:42:01 +02:00
|
|
|
{
|
2009-07-08 16:34:17 +02:00
|
|
|
temp = (transaction->tra_flags & TRA_rec_version) ?
|
2006-07-19 09:07:54 +02:00
|
|
|
iso_mode_rc_version : iso_mode_rc_no_version;
|
2008-04-19 11:42:01 +02:00
|
|
|
}
|
2006-07-17 19:44:18 +02:00
|
|
|
else
|
2009-07-06 11:19:26 +02:00
|
|
|
{
|
2006-10-30 13:39:08 +01:00
|
|
|
temp = iso_mode_concurrency;
|
2009-07-06 11:19:26 +02:00
|
|
|
}
|
|
|
|
record.storeInteger(f_mon_tra_iso_mode, temp);
|
2006-07-17 19:44:18 +02:00
|
|
|
// lock timeout
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_tra_lock_timeout, transaction->tra_lock_timeout);
|
2006-07-17 19:44:18 +02:00
|
|
|
// read only flag
|
2007-09-14 17:13:19 +02:00
|
|
|
temp = (transaction->tra_flags & TRA_readonly) ? 1 : 0;
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_tra_read_only, temp);
|
2006-07-17 19:44:18 +02:00
|
|
|
// autocommit flag
|
2007-09-14 17:13:19 +02:00
|
|
|
temp = (transaction->tra_flags & TRA_autocommit) ? 1 : 0;
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_tra_auto_commit, temp);
|
2006-07-17 19:44:18 +02:00
|
|
|
// auto undo flag
|
2007-09-14 17:13:19 +02:00
|
|
|
temp = (transaction->tra_flags & TRA_no_auto_undo) ? 0 : 1;
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_tra_auto_undo, temp);
|
|
|
|
|
2007-09-14 17:13:19 +02:00
|
|
|
// statistics
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeGlobalId(f_mon_tra_stat_id, getGlobalId(stat_id));
|
|
|
|
writer.putRecord(record);
|
2008-02-20 14:13:22 +01:00
|
|
|
putStatistics(transaction->tra_stats, writer, stat_id, stat_transaction);
|
2008-05-06 10:46:39 +02:00
|
|
|
putMemoryUsage(transaction->tra_memory_stats, writer, stat_id, stat_transaction);
|
2006-07-17 19:44:18 +02:00
|
|
|
}
|
|
|
|
|
2006-07-17 21:26:43 +02:00
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
void DatabaseSnapshot::putRequest(const jrd_req* request, Writer& writer, int stat_id)
|
2006-07-17 19:44:18 +02:00
|
|
|
{
|
2006-10-30 13:39:08 +01:00
|
|
|
fb_assert(request);
|
2006-07-17 21:26:43 +02:00
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
DumpRecord record(rel_mon_statements);
|
2006-07-17 19:44:18 +02:00
|
|
|
|
|
|
|
// request id
|
2011-02-14 18:05:23 +01:00
|
|
|
record.storeInteger(f_mon_stmt_id, request->req_id);
|
2006-07-17 19:44:18 +02:00
|
|
|
// attachment id
|
2009-07-06 11:19:26 +02:00
|
|
|
if (request->req_attachment)
|
|
|
|
{
|
|
|
|
record.storeInteger(f_mon_stmt_att_id, request->req_attachment->att_attachment_id);
|
2006-07-17 19:44:18 +02:00
|
|
|
}
|
2007-03-05 08:50:23 +01:00
|
|
|
// state, transaction ID, timestamp
|
2009-07-06 11:19:26 +02:00
|
|
|
if (request->req_flags & req_active)
|
|
|
|
{
|
2008-08-25 08:58:35 +02:00
|
|
|
const bool is_stalled = (request->req_flags & req_stall);
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_stmt_state, is_stalled ? mon_state_stalled : mon_state_active);
|
|
|
|
if (request->req_transaction)
|
|
|
|
{
|
|
|
|
record.storeInteger(f_mon_stmt_tra_id, request->req_transaction->tra_number);
|
|
|
|
}
|
|
|
|
record.storeTimestamp(f_mon_stmt_timestamp, request->req_timestamp);
|
2006-07-17 19:44:18 +02:00
|
|
|
}
|
2009-07-06 11:19:26 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
record.storeInteger(f_mon_stmt_state, mon_state_idle);
|
2007-03-05 08:50:23 +01:00
|
|
|
}
|
|
|
|
// sql text
|
2009-07-06 11:19:26 +02:00
|
|
|
if (request->req_sql_text)
|
|
|
|
{
|
|
|
|
record.storeString(f_mon_stmt_sql_text, *request->req_sql_text);
|
|
|
|
}
|
|
|
|
|
2007-09-14 17:13:19 +02:00
|
|
|
// statistics
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeGlobalId(f_mon_stmt_stat_id, getGlobalId(stat_id));
|
|
|
|
writer.putRecord(record);
|
2008-02-20 14:13:22 +01:00
|
|
|
putStatistics(request->req_stats, writer, stat_id, stat_statement);
|
2008-05-06 10:46:39 +02:00
|
|
|
putMemoryUsage(request->req_memory_stats, writer, stat_id, stat_statement);
|
2007-03-05 08:50:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
void DatabaseSnapshot::putCall(const jrd_req* request, Writer& writer, int stat_id)
|
2007-03-05 08:50:23 +01:00
|
|
|
{
|
|
|
|
fb_assert(request);
|
|
|
|
|
2008-04-19 11:42:01 +02:00
|
|
|
const jrd_req* statement = request->req_caller;
|
2007-03-05 08:50:23 +01:00
|
|
|
while (statement->req_caller)
|
2009-07-06 11:19:26 +02:00
|
|
|
{
|
2007-03-05 08:50:23 +01:00
|
|
|
statement = statement->req_caller;
|
2009-07-06 11:19:26 +02:00
|
|
|
}
|
2007-03-05 08:50:23 +01:00
|
|
|
fb_assert(statement);
|
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
DumpRecord record(rel_mon_calls);
|
2007-03-05 08:50:23 +01:00
|
|
|
|
|
|
|
// call id
|
2011-02-14 18:05:23 +01:00
|
|
|
record.storeInteger(f_mon_call_id, request->req_id);
|
2007-03-05 08:50:23 +01:00
|
|
|
// statement id
|
2011-02-14 18:05:23 +01:00
|
|
|
record.storeInteger(f_mon_call_stmt_id, statement->req_id);
|
2007-03-05 08:50:23 +01:00
|
|
|
// caller id
|
2009-07-06 11:19:26 +02:00
|
|
|
if (statement != request->req_caller)
|
|
|
|
{
|
2011-02-14 18:05:23 +01:00
|
|
|
record.storeInteger(f_mon_call_caller_id, request->req_caller->req_id);
|
2007-03-05 08:50:23 +01:00
|
|
|
}
|
|
|
|
// object name/type
|
2009-07-06 11:19:26 +02:00
|
|
|
if (request->req_procedure)
|
|
|
|
{
|
|
|
|
record.storeString(f_mon_call_name, request->req_procedure->prc_name);
|
|
|
|
record.storeInteger(f_mon_call_type, obj_procedure);
|
2007-03-05 08:50:23 +01:00
|
|
|
}
|
2009-07-06 11:19:26 +02:00
|
|
|
else if (!request->req_trg_name.isEmpty())
|
|
|
|
{
|
|
|
|
record.storeString(f_mon_call_name, request->req_trg_name);
|
|
|
|
record.storeInteger(f_mon_call_type, obj_trigger);
|
2007-03-05 08:50:23 +01:00
|
|
|
}
|
2009-07-06 11:19:26 +02:00
|
|
|
else
|
|
|
|
{
|
2007-03-05 08:50:23 +01:00
|
|
|
// we should never be here...
|
|
|
|
fb_assert(false);
|
2006-07-17 19:44:18 +02:00
|
|
|
}
|
2006-10-30 13:39:08 +01:00
|
|
|
// timestamp
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeTimestamp(f_mon_call_timestamp, request->req_timestamp);
|
2007-03-05 08:50:23 +01:00
|
|
|
// source line/column
|
2009-07-06 11:19:26 +02:00
|
|
|
if (request->req_src_line)
|
|
|
|
{
|
|
|
|
record.storeInteger(f_mon_call_src_line, request->req_src_line);
|
|
|
|
record.storeInteger(f_mon_call_src_column, request->req_src_column);
|
|
|
|
}
|
|
|
|
|
2007-09-14 17:13:19 +02:00
|
|
|
// statistics
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeGlobalId(f_mon_call_stat_id, getGlobalId(stat_id));
|
|
|
|
writer.putRecord(record);
|
2008-02-20 14:13:22 +01:00
|
|
|
putStatistics(request->req_stats, writer, stat_id, stat_call);
|
2008-05-06 10:46:39 +02:00
|
|
|
putMemoryUsage(request->req_memory_stats, writer, stat_id, stat_call);
|
2007-09-14 17:13:19 +02:00
|
|
|
}
|
|
|
|
|
2008-02-20 14:13:22 +01:00
|
|
|
void DatabaseSnapshot::putStatistics(const RuntimeStatistics& statistics,
|
2009-07-06 11:19:26 +02:00
|
|
|
Writer& writer,
|
|
|
|
int stat_id, int stat_group)
|
2007-09-14 17:13:19 +02:00
|
|
|
{
|
|
|
|
// statistics id
|
|
|
|
const SINT64 id = getGlobalId(stat_id);
|
|
|
|
|
|
|
|
// physical I/O statistics
|
2009-07-06 11:19:26 +02:00
|
|
|
DumpRecord record(rel_mon_io_stats);
|
|
|
|
record.storeGlobalId(f_mon_io_stat_id, id);
|
|
|
|
record.storeInteger(f_mon_io_stat_group, stat_group);
|
|
|
|
record.storeInteger(f_mon_io_page_reads, statistics.getValue(RuntimeStatistics::PAGE_READS));
|
|
|
|
record.storeInteger(f_mon_io_page_writes, statistics.getValue(RuntimeStatistics::PAGE_WRITES));
|
|
|
|
record.storeInteger(f_mon_io_page_fetches, statistics.getValue(RuntimeStatistics::PAGE_FETCHES));
|
|
|
|
record.storeInteger(f_mon_io_page_marks, statistics.getValue(RuntimeStatistics::PAGE_MARKS));
|
|
|
|
writer.putRecord(record);
|
2007-09-14 17:13:19 +02:00
|
|
|
|
|
|
|
// logical I/O statistics
|
2009-07-06 11:19:26 +02:00
|
|
|
record.reset(rel_mon_rec_stats);
|
|
|
|
record.storeGlobalId(f_mon_rec_stat_id, id);
|
|
|
|
record.storeInteger(f_mon_rec_stat_group, stat_group);
|
|
|
|
record.storeInteger(f_mon_rec_seq_reads, statistics.getValue(RuntimeStatistics::RECORD_SEQ_READS));
|
|
|
|
record.storeInteger(f_mon_rec_idx_reads, statistics.getValue(RuntimeStatistics::RECORD_IDX_READS));
|
|
|
|
record.storeInteger(f_mon_rec_inserts, statistics.getValue(RuntimeStatistics::RECORD_INSERTS));
|
|
|
|
record.storeInteger(f_mon_rec_updates, statistics.getValue(RuntimeStatistics::RECORD_UPDATES));
|
|
|
|
record.storeInteger(f_mon_rec_deletes, statistics.getValue(RuntimeStatistics::RECORD_DELETES));
|
|
|
|
record.storeInteger(f_mon_rec_backouts, statistics.getValue(RuntimeStatistics::RECORD_BACKOUTS));
|
|
|
|
record.storeInteger(f_mon_rec_purges, statistics.getValue(RuntimeStatistics::RECORD_PURGES));
|
|
|
|
record.storeInteger(f_mon_rec_expunges, statistics.getValue(RuntimeStatistics::RECORD_EXPUNGES));
|
|
|
|
writer.putRecord(record);
|
2008-02-20 14:13:22 +01:00
|
|
|
}
|
|
|
|
|
2009-02-08 13:57:49 +01:00
|
|
|
void DatabaseSnapshot::putContextVars(const StringMap& variables,
|
2009-07-06 11:19:26 +02:00
|
|
|
Writer& writer,
|
2008-02-20 14:13:22 +01:00
|
|
|
int object_id, bool is_attachment)
|
|
|
|
{
|
2009-02-08 13:57:49 +01:00
|
|
|
StringMap::ConstAccessor accessor(&variables);
|
2008-12-19 15:57:01 +01:00
|
|
|
|
|
|
|
for (bool found = accessor.getFirst(); found; found = accessor.getNext())
|
2008-02-20 14:13:22 +01:00
|
|
|
{
|
2009-07-06 11:19:26 +02:00
|
|
|
DumpRecord record(rel_mon_ctx_vars);
|
2008-02-20 14:13:22 +01:00
|
|
|
|
|
|
|
if (is_attachment)
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_ctx_var_att_id, object_id);
|
2008-02-20 14:13:22 +01:00
|
|
|
else
|
2009-07-06 11:19:26 +02:00
|
|
|
record.storeInteger(f_mon_ctx_var_tra_id, object_id);
|
|
|
|
|
|
|
|
record.storeString(f_mon_ctx_var_name, accessor.current()->first);
|
|
|
|
record.storeString(f_mon_ctx_var_value, accessor.current()->second);
|
2008-02-20 14:13:22 +01:00
|
|
|
|
2009-07-06 11:19:26 +02:00
|
|
|
writer.putRecord(record);
|
2008-02-20 14:13:22 +01:00
|
|
|
}
|
2006-07-17 19:44:18 +02:00
|
|
|
}
|
2008-05-06 10:46:39 +02:00
|
|
|
|
2008-12-20 09:12:19 +01:00
|
|
|
void DatabaseSnapshot::putMemoryUsage(const MemoryStats& stats,
|
2009-07-06 11:19:26 +02:00
|
|
|
Writer& writer,
|
2008-05-06 10:46:39 +02:00
|
|
|
int stat_id,
|
|
|
|
int stat_group)
|
|
|
|
{
|
|
|
|
// statistics id
|
|
|
|
const SINT64 id = getGlobalId(stat_id);
|
|
|
|
|
|
|
|
// memory usage
|
2009-07-06 11:19:26 +02:00
|
|
|
DumpRecord record(rel_mon_mem_usage);
|
|
|
|
record.storeGlobalId(f_mon_mem_stat_id, id);
|
|
|
|
record.storeInteger(f_mon_mem_stat_group, stat_group);
|
|
|
|
record.storeInteger(f_mon_mem_cur_used, stats.getCurrentUsage());
|
|
|
|
record.storeInteger(f_mon_mem_cur_alloc, stats.getCurrentMapping());
|
|
|
|
record.storeInteger(f_mon_mem_max_used, stats.getMaximumUsage());
|
|
|
|
record.storeInteger(f_mon_mem_max_alloc, stats.getMaximumMapping());
|
|
|
|
|
|
|
|
writer.putRecord(record);
|
2008-05-06 10:46:39 +02:00
|
|
|
}
|