Commit ef1b8cb1 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Don't hand out zero VXIDs we need that as a magic value.

parent 4c4d6f65
...@@ -937,7 +937,7 @@ void *VSM_Alloc(unsigned size, const char *class, const char *type, ...@@ -937,7 +937,7 @@ void *VSM_Alloc(unsigned size, const char *class, const char *type,
void VSL_Setup(struct vsl_log *vsl, void *ptr, size_t len); void VSL_Setup(struct vsl_log *vsl, void *ptr, size_t len);
void VSM_Free(void *ptr); void VSM_Free(void *ptr);
#ifdef VSL_ENDMARKER #ifdef VSL_ENDMARKER
void VSL(enum VSL_tag_e tag, int id, const char *fmt, ...) void VSL(enum VSL_tag_e tag, uint32_t vxid, const char *fmt, ...)
__printflike(3, 4); __printflike(3, 4);
void VSLb(struct vsl_log *, enum VSL_tag_e tag, const char *fmt, ...) void VSLb(struct vsl_log *, enum VSL_tag_e tag, const char *fmt, ...)
__printflike(3, 4); __printflike(3, 4);
......
...@@ -87,30 +87,29 @@ THR_GetName(void) ...@@ -87,30 +87,29 @@ THR_GetName(void)
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
* VXID's are unique transaction numbers allocated with a minimum of * VXID's are unique transaction numbers allocated with a minimum of
* locking overhead via pools in the worker threads. * locking overhead via pools in the worker threads.
*
* VXID's are mostly for use in VSL and for that reason we never return
* zero vxid, in order to reserve that for "unassociated" VSL records.
*/ */
static uint32_t vxid_base; static uint32_t vxid_base;
static struct lock vxid_lock; static struct lock vxid_lock;
static void
vxid_More(struct vxid_pool *v)
{
Lck_Lock(&vxid_lock);
v->next = vxid_base;
v->count = 32768;
vxid_base = v->count;
Lck_Unlock(&vxid_lock);
}
uint32_t uint32_t
VXID_Get(struct vxid_pool *v) VXID_Get(struct vxid_pool *v)
{ {
if (v->count == 0) do {
vxid_More(v); if (v->count == 0) {
AN(v->count); Lck_Lock(&vxid_lock);
v->count--; v->next = vxid_base;
return (v->next++); v->count = 32768;
vxid_base = v->count;
Lck_Unlock(&vxid_lock);
}
v->count--;
v->next++;
} while (v->next == 0);
return (v->next);
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
......
...@@ -61,12 +61,12 @@ vsl_w0(uint32_t type, uint32_t length) ...@@ -61,12 +61,12 @@ vsl_w0(uint32_t type, uint32_t length)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
static inline void static inline void
vsl_hdr(enum VSL_tag_e tag, uint32_t *p, unsigned len, unsigned id) vsl_hdr(enum VSL_tag_e tag, uint32_t *p, unsigned len, uint32_t vxid)
{ {
assert(((uintptr_t)p & 0x3) == 0); assert(((uintptr_t)p & 0x3) == 0);
p[1] = id; p[1] = vxid;
VMB(); VMB();
p[0] = vsl_w0(tag, len); p[0] = vsl_w0(tag, len);
} }
...@@ -133,7 +133,7 @@ vsl_get(unsigned len, unsigned records, unsigned flushes) ...@@ -133,7 +133,7 @@ vsl_get(unsigned len, unsigned records, unsigned flushes)
*/ */
static void static void
vslr(enum VSL_tag_e tag, int id, const char *b, unsigned len) vslr(enum VSL_tag_e tag, uint32_t vxid, const char *b, unsigned len)
{ {
uint32_t *p; uint32_t *p;
unsigned mlen; unsigned mlen;
...@@ -147,13 +147,13 @@ vslr(enum VSL_tag_e tag, int id, const char *b, unsigned len) ...@@ -147,13 +147,13 @@ vslr(enum VSL_tag_e tag, int id, const char *b, unsigned len)
p = vsl_get(len, 1, 0); p = vsl_get(len, 1, 0);
memcpy(p + 2, b, len); memcpy(p + 2, b, len);
vsl_hdr(tag, p, len, id); vsl_hdr(tag, p, len, vxid);
} }
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
void void
VSL(enum VSL_tag_e tag, int id, const char *fmt, ...) VSL(enum VSL_tag_e tag, uint32_t vxid, const char *fmt, ...)
{ {
va_list ap; va_list ap;
unsigned n, mlen = cache_param->shm_reclen; unsigned n, mlen = cache_param->shm_reclen;
...@@ -167,12 +167,12 @@ VSL(enum VSL_tag_e tag, int id, const char *fmt, ...) ...@@ -167,12 +167,12 @@ VSL(enum VSL_tag_e tag, int id, const char *fmt, ...)
va_start(ap, fmt); va_start(ap, fmt);
if (strchr(fmt, '%') == NULL) { if (strchr(fmt, '%') == NULL) {
vslr(tag, id, fmt, strlen(fmt)); vslr(tag, vxid, fmt, strlen(fmt));
} else { } else {
n = vsnprintf(buf, mlen, fmt, ap); n = vsnprintf(buf, mlen, fmt, ap);
if (n > mlen) if (n > mlen)
n = mlen; n = mlen;
vslr(tag, id, buf, n); vslr(tag, vxid, buf, n);
} }
va_end(ap); va_end(ap);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment