|
1 | 1 | //-----------------------------------------------------------------------------
|
2 |
| -// Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved. |
| 2 | +// Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | //
|
4 | 4 | // Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
|
5 | 5 | //
|
|
14 | 14 |
|
15 | 15 | #include "cxoModule.h"
|
16 | 16 |
|
| 17 | +// forward declarations |
| 18 | +int cxoSessionPool_reconfigureHelper(cxoSessionPool *pool, |
| 19 | + const char *attrName, PyObject *value); |
| 20 | + |
| 21 | + |
17 | 22 | //-----------------------------------------------------------------------------
|
18 | 23 | // cxoSessionPool_new()
|
19 | 24 | // Create a new session pool object.
|
@@ -338,6 +343,93 @@ static PyObject *cxoSessionPool_drop(cxoSessionPool *pool, PyObject *args)
|
338 | 343 | }
|
339 | 344 |
|
340 | 345 |
|
| 346 | +//----------------------------------------------------------------------------- |
| 347 | +// cxoSessionPool_reconfigure() |
| 348 | +// Reconfigure properties of the session pool. |
| 349 | +//----------------------------------------------------------------------------- |
| 350 | +static PyObject *cxoSessionPool_reconfigure(cxoSessionPool *pool, |
| 351 | + PyObject *args, PyObject *keywordArgs) |
| 352 | +{ |
| 353 | + PyObject *timeout, *waitTimeout, *maxLifetimeSession, *maxSessionsPerShard; |
| 354 | + PyObject *sodaMetadataCache, *stmtcachesize, *pingInterval, *getMode; |
| 355 | + uint32_t minSessions, maxSessions, sessionIncrement; |
| 356 | + |
| 357 | + // define keyword arguments |
| 358 | + static char *keywordList[] = { "min", "max", "increment", "getmode", |
| 359 | + "timeout", "wait_timeout", "max_lifetime_session", |
| 360 | + "max_sessions_per_shard", "soda_metadata_cache", "stmtcachesize", |
| 361 | + "ping_interval", NULL }; |
| 362 | + |
| 363 | + // set up default values |
| 364 | + minSessions = pool->minSessions; |
| 365 | + maxSessions = pool->maxSessions; |
| 366 | + sessionIncrement = pool->sessionIncrement; |
| 367 | + timeout = waitTimeout = maxLifetimeSession = maxSessionsPerShard = NULL; |
| 368 | + sodaMetadataCache = stmtcachesize = pingInterval = getMode = NULL; |
| 369 | + |
| 370 | + // parse arguments and keywords |
| 371 | + if (!PyArg_ParseTupleAndKeywords(args, keywordArgs, "|iiiOOOOOOOO", |
| 372 | + keywordList, &minSessions, &maxSessions, &sessionIncrement, |
| 373 | + &getMode, &timeout, &waitTimeout, &maxLifetimeSession, |
| 374 | + &maxSessionsPerShard, &sodaMetadataCache, &stmtcachesize, |
| 375 | + &pingInterval)) |
| 376 | + return NULL; |
| 377 | + |
| 378 | + // perform reconfiguration of the pool itself if needed |
| 379 | + if (minSessions != pool->minSessions || maxSessions != pool->maxSessions || |
| 380 | + sessionIncrement != pool->sessionIncrement) { |
| 381 | + if (dpiPool_reconfigure(pool->handle, minSessions, maxSessions, |
| 382 | + sessionIncrement) < 0) |
| 383 | + return cxoError_raiseAndReturnNull(); |
| 384 | + pool->minSessions = minSessions; |
| 385 | + pool->maxSessions = maxSessions; |
| 386 | + pool->sessionIncrement = sessionIncrement; |
| 387 | + } |
| 388 | + |
| 389 | + // adjust attributes |
| 390 | + if (cxoSessionPool_reconfigureHelper(pool, "getmode", getMode) < 0) |
| 391 | + return NULL; |
| 392 | + if (cxoSessionPool_reconfigureHelper(pool, "timeout", timeout) < 0) |
| 393 | + return NULL; |
| 394 | + if (cxoSessionPool_reconfigureHelper(pool, "wait_timeout", |
| 395 | + waitTimeout) < 0) |
| 396 | + return NULL; |
| 397 | + if (cxoSessionPool_reconfigureHelper(pool, "max_lifetime_session", |
| 398 | + maxLifetimeSession) < 0) |
| 399 | + return NULL; |
| 400 | + if (cxoSessionPool_reconfigureHelper(pool, "max_sessions_per_shard", |
| 401 | + maxSessionsPerShard) < 0) |
| 402 | + return NULL; |
| 403 | + if (cxoSessionPool_reconfigureHelper(pool, "soda_metadata_cache", |
| 404 | + sodaMetadataCache) < 0) |
| 405 | + return NULL; |
| 406 | + if (cxoSessionPool_reconfigureHelper(pool, "stmtcachesize", |
| 407 | + stmtcachesize) < 0) |
| 408 | + return NULL; |
| 409 | + if (cxoSessionPool_reconfigureHelper(pool, "ping_interval", |
| 410 | + pingInterval) < 0) |
| 411 | + return NULL; |
| 412 | + |
| 413 | + Py_RETURN_NONE; |
| 414 | +} |
| 415 | + |
| 416 | + |
| 417 | +//----------------------------------------------------------------------------- |
| 418 | +// cxoSessionPool_reconfigureHelpe() |
| 419 | +// Helper function that calls the setter for the session pool's property, |
| 420 | +// after first checking that a value was supplied and not None. |
| 421 | +//----------------------------------------------------------------------------- |
| 422 | +int cxoSessionPool_reconfigureHelper(cxoSessionPool *pool, |
| 423 | + const char *attrName, PyObject *value) |
| 424 | +{ |
| 425 | + if (value != NULL && value != Py_None) { |
| 426 | + if (PyObject_SetAttrString((PyObject*) pool, attrName, value) < 0) |
| 427 | + return cxoError_raiseAndReturnInt(); |
| 428 | + } |
| 429 | + return 0; |
| 430 | +} |
| 431 | + |
| 432 | + |
341 | 433 | //-----------------------------------------------------------------------------
|
342 | 434 | // cxoSessionPool_release()
|
343 | 435 | // Release a connection back to the session pool.
|
@@ -455,6 +547,17 @@ static PyObject *cxoSessionPool_getMaxLifetimeSession(cxoSessionPool *pool,
|
455 | 547 | }
|
456 | 548 |
|
457 | 549 |
|
| 550 | +//----------------------------------------------------------------------------- |
| 551 | +// cxoSessionPool_getMaxSessionsPerShard() |
| 552 | +// Return the maximum sessions per shard in the session pool. |
| 553 | +//----------------------------------------------------------------------------- |
| 554 | +static PyObject *cxoSessionPool_getMaxSessionsPerShard(cxoSessionPool *pool, |
| 555 | + void *unused) |
| 556 | +{ |
| 557 | + return cxoSessionPool_getAttribute(pool, dpiPool_getMaxSessionsPerShard); |
| 558 | +} |
| 559 | + |
| 560 | + |
458 | 561 | //-----------------------------------------------------------------------------
|
459 | 562 | // cxoSessionPool_getOpenCount()
|
460 | 563 | // Return the number of open connections in the session pool.
|
@@ -559,6 +662,18 @@ static int cxoSessionPool_setMaxLifetimeSession(cxoSessionPool *pool,
|
559 | 662 | }
|
560 | 663 |
|
561 | 664 |
|
| 665 | +//----------------------------------------------------------------------------- |
| 666 | +// cxoSessionPool_setMaxSessionsPerShard() |
| 667 | +// Set the maximum lifetime for connections in the session pool. |
| 668 | +//----------------------------------------------------------------------------- |
| 669 | +static int cxoSessionPool_setMaxSessionsPerShard(cxoSessionPool *pool, |
| 670 | + PyObject *value, void *unused) |
| 671 | +{ |
| 672 | + return cxoSessionPool_setAttribute(pool, value, |
| 673 | + dpiPool_setMaxSessionsPerShard); |
| 674 | +} |
| 675 | + |
| 676 | + |
562 | 677 | //-----------------------------------------------------------------------------
|
563 | 678 | // cxoSessionPool_setPingInterval()
|
564 | 679 | // Set the value of the OCI attribute.
|
@@ -649,6 +764,8 @@ static PyMethodDef cxoMethods[] = {
|
649 | 764 | { "close", (PyCFunction) cxoSessionPool_close,
|
650 | 765 | METH_VARARGS | METH_KEYWORDS },
|
651 | 766 | { "drop", (PyCFunction) cxoSessionPool_drop, METH_VARARGS },
|
| 767 | + { "reconfigure", (PyCFunction) cxoSessionPool_reconfigure, |
| 768 | + METH_VARARGS | METH_KEYWORDS }, |
652 | 769 | { "release", (PyCFunction) cxoSessionPool_release,
|
653 | 770 | METH_VARARGS | METH_KEYWORDS },
|
654 | 771 | { NULL }
|
@@ -684,6 +801,8 @@ static PyGetSetDef cxoCalcMembers[] = {
|
684 | 801 | (setter) cxoSessionPool_setGetMode, 0, 0 },
|
685 | 802 | { "max_lifetime_session", (getter) cxoSessionPool_getMaxLifetimeSession,
|
686 | 803 | (setter) cxoSessionPool_setMaxLifetimeSession, 0, 0 },
|
| 804 | + { "max_sessions_per_shard", (getter) cxoSessionPool_getMaxSessionsPerShard, |
| 805 | + (setter) cxoSessionPool_setMaxSessionsPerShard, 0, 0 }, |
687 | 806 | { "ping_interval", (getter) cxoSessionPool_getPingInterval,
|
688 | 807 | (setter) cxoSessionPool_setPingInterval, 0, 0 },
|
689 | 808 | { "soda_metadata_cache", (getter) cxoSessionPool_getSodaMetadataCache,
|
|
0 commit comments