34 Commits

Author SHA1 Message Date
Erik Nordström
882a247244 Support compiler-agnostic annotations
This change adds a compiler-agnostic annotation for fall-throughs in
switch statements. The definition is put in `annotations.h`, which can
be expanded to hold definitions for similar functionality in the
future.

The `clang` compiler (as of version 12) seems to have have dropped
support for the previous comment-based annotations to allow
fall-throughs in favor of native annotations or GCC-style attributes.
2020-09-29 06:54:24 +02:00
Dmitry Simonenko
23eeecc4e5 Do not forward relcache invalidation as syscache invalidation
It is incorrect to forward relcache invalidations as syscache
invalidations, like cacheid = InvalidOid which is not possible
condition at the moment. Allow syscache invalidations only for
FOREIGNSERVEROIDs.
2020-06-29 17:13:22 +03:00
Erik Nordström
9d533f31c2 Improve connection handling during transactions
This change refactors how connections are handled during remote
transactions. In particular, the connection cache now stays consistent
during transactions, even during rollbacks. Previously, the connection
cache was replaced on every rollback, even if the rollback was
intentional (i.e, not due to an error). This made it hard to debug
connections since the cache became completely empty.

Connections could also be left in the cache in a bad state after
failed transactions. This has been fixed by moving connection checks
to the cache and tying transaction state changes to each
connection. This ensures that such checks are done in one canonical
place instead of being spread out throughout the code.

Given how tightly coupled a remote transaction is with its connection,
it might make sense to remove the separate remote transaction store
and instead put this information in each connection. This is left to a
future change, however.

In addition to the above changes, this commit includes:

* Showing transaction depth and invalidation in the transaction store
* Invalidation on individual connections instead of replacing the
  whole cache
* Closing of connections to a local database that is being dropped to
  prevent "in use" errors.
* Ability to add callbacks to async requests that are executed when a
  response is received. This is used by remote transactions to mark
  connections as having successfully completed a transaction. Thus, on
  errors, it is easy to detect connections that are in bad states.
* Error checks on each connection instead of having global error
  tracking for each remote transaction. This change removes the global
  error state for distributed transactions.
2020-06-13 12:05:41 +02:00
Dmitry Simonenko
79f6223631 Replace UserMappings with a connection ID
This change replace UserMappings with newly introduced TSConnectionId
object, which represent a pair of foreign server id and local user id.

Authentication has been moved to non-password based, since original
UserMappings were used to store a data node user passwords as
well. This is a temporary step, until introduction of certificate
based authentication.

List of changes:

* add_data_node() password and bootstrap_password arguments removed

* introduced authentication using pgpass file

* RemoteTxn format string which represents tx changed to
  tx-version-xid-server_id-user_id

* data_node_dispatch, remote transaction cache, connection cache hash
  tables keys switched to TSConnectionId instead of user mappings

* remote_connection_open() been rework to exclude user options

* Tests upgraded, user mappings and passwords usage has been excluded
2020-05-27 17:31:09 +02:00
Matvey Arye
02c178d9ca Add connection caching infrastructure
This commit adds the ability to cache remote connections
across commands and transactions. This is needed since establishing
new connections is expensive. The cache is invalidated
when the foreign server or user mapping is changed. Because of this
the cache is tied to a user mapping (it is keyed by the user mapping's
oid and requires a user_mapping for invalidation).

We use the syscache invalidation mechanism since foreign servers and
user mappings are already invalidated using this mechanism. This
requires some extra plumbing in our cache invalidation handling.

This cache will be used in txn callback handling and so the regular
auto-release of caches on (sub)txn commits/aborts that happens
with most caches is inappropriate. Therefore we added a new flag
to the cache called `handle_txn_callbacks` that allows a cache
to turn off the auto-release mechanism
2020-05-27 17:31:09 +02:00
gayyappan
b363e8a379 Fix cache invalidation code
Cache invalidation code does not call the
bgw invalidate cache callback when all caches
have to be invalidated.
2020-03-04 13:53:15 -05:00
Matvey Arye
34edba16a9 Run clang-format on code 2019-02-05 16:55:16 -05:00
Joshua Lockerman
acc41a7712 Update license header
Only have the copyright in the NOTICE. Hopefully
only having to update one place each year will
keep it consistent.
2019-01-03 11:57:51 -05:00
Sven Klemm
92586d8fc9 Fix typos in comments 2018-12-31 18:36:05 +01:00
Joshua Lockerman
9de504f958 Add ts_ prefix to everything in headers
Future proofing: if we ever want to make our functions available  to
others they’d need to be prefixed to prevent name collisions. In
order to avoid having some functions with the ts_ prefix and
others without, we’re adding the prefix to all non-static
functions now.
2018-12-05 14:43:22 -05:00
Amy Tai
b77b47ada8 Enable scheduler to update its jobs list
Previously, the scheduler only populated its jobs list once at start time. This commit enables the scheduler to receive notifications for updates (insert, update, delete) to the bgw_job table. Notifications are sent via the cache invalidation framework. Whenever the scheduler receives a notification, it re-reads the bgw_job table. For each job currently in the bgw_job table, it either instantiates new scheduler state for the job or copies over any existing scheduler state, for persisting jobs. For jobs that have disappeared from the bgw_job table, the scheduler deletes any local state it has.

Note that any updates to the bgw_job table must now go through the C, so that the cache invalidation framework in catalog.c can run. In particular, this commit includes a rudimentary API for interacting with the bgw_job table, for testing purposes. This API will be rewritten in the future.
2018-11-07 15:53:04 -05:00
Joshua Lockerman
d8e41ddaba Add Apache License header to all C files 2018-10-29 13:28:19 -04:00
Joshua Lockerman
974788516a Prefix public C functions with ts_
We've decided to adopt the ts_ prefix on all exported C functions in
order to avoid having symbol conflicts with future postgres functions.
We've already started using this prefix on new functions and this commit
adds the prefix to to the old functions.
2018-09-27 11:45:04 -04:00
Erik Nordström
db39eddf2e Remove unused cache invalidation triggers
The cache invalidation triggers on our catalog tables
aren't used anymore as all modifications to catalog tables
happen using the C API, which doesn't invoke triggers and
has its own cache invalidation functionality.
2018-02-26 20:10:31 +01:00
Matvey Arye
25f3284466 Handle cache invalidation during subtxn rollback
Add logic to invalidate the cache during subtxn rollback.

Fixes #376
2018-01-11 09:35:37 -05:00
Rob Kiefer
66396fb81e Add build support for Windows
Windows 64-bit binaries should now be buildable using the cmake
build system either from the command line or from Visual Studio.

Previous issues regarding unresolved symbols have been resolved
with compatibility header files to properly export symbols or
getting GUCs via normal APIs.
2017-11-27 12:04:44 -05:00
Erik Nordström
e1a0e819cf Refactor and fix cache invalidation
TimescaleDB cache invalidation happens as a side effect of doing a
full SQL statement (INSERT/UPDATE/DELETE) on a catalog table (via
table triggers). However, triggers aren't invoked when using
PostgreSQL's internal catalog API for updates, since PostgreSQL's
catalog tables don't have triggers that require full statement
parsing, planning, and execution.

Since we are now using the regular PostgreSQL catalog update API for
some TimescaleDB catalog operations, we need to do cache invalidation
also on such operations.

This change adds cache invalidation when updating catalogs using the
internal (C) API and also makes the cache invalidation more fine
grained. For instance, caches are no longer invalidated on some
INSERTS that do not affect the validity of objects already in the
cache, such as adding a new chunk.
2017-11-27 17:33:10 +01:00
Erik Nordström
e1d01b9fff Fix pgindent issues due to windows-related changes
Files that have been modified with the PGDLLEXPORT macro
are no longer pgindent formatted. This change fixes these
pgindent issues.
2017-10-05 16:34:27 +02:00
Rob Kiefer
b57e2bf1f4 Prepare C code for compiling on Windows
For all exported functions the macro PGDLLEXPORT needs to be pre-
pended. Additionally, on Windows `open` is a macro that needed to
be renamed. A few other small changes are done to make Visual
Studio's compiler happy / get rid of warnings (e.g. adding return
statements after elog).
2017-10-03 16:54:34 -04:00
Matvey Arye
4dcbe6114d Add support for hypertable constraints
This PR add support for primary-key, foreign-key, unique, and exclusion constraints.
Previously supported are CHECK and NOT NULL constraints. Now, foreign key
constraints where a hypertable references a plain table is support
(while vice versa, with a plain table references a hypertable, is still not).
2017-09-07 11:31:48 -04:00
Matvey Arye
aca7f326b3 Fix extension drop handling
Previously, the extension could end up in a bad state if it
was dropped as part of a cascade. This PR fixes that by
checking explicitly for the presence of the proxy table
to make sure we are not in the middle of an extension
drop. Fixes #73.
2017-06-27 10:57:10 -04:00
Erik Nordström
e75cd7e66b Finer grained memory management
Also fix a number of memory allocation bugs
and properly initialize chunks that are allocated
during a scan for chunks.
2017-06-22 20:15:38 +02:00
Matvey Arye
eb32081085 Fix Invalid database ID error
This fixes a superfluous error that happened during cache invalidation.
2017-05-16 09:56:00 -04:00
Matvey Arye
e87bc774d7 Fix logic for when entire cache is invalidated
Sometimes postgres wants to invalidate the entire cache. In this case it
send a cache invalidation message with relid == InvalidOid. This should
invalidate all the caches. Previously, it did not effect the cache of
the extension state. This fixes that problem and creates one cache reset
code path for both extension dropping and whole-cache reset, cleaning
up some of the logic in the process.
2017-03-31 17:31:34 -04:00
Erik Nordström
c60b08e83a Fix DROP EXTENSION
DROP EXTENSION didn't properly reset caches and other saved state
causing various errors related to bad state when the extension was
dropped and/or recreated later.

This patch adds functionality to track the state of the extension and
also signals DROP EXTENSION to other backends that might be running,
allowing them to reset their internal extension state.
2017-03-22 19:43:40 +01:00
Erik Nordström
001c41f84a Rename IobeamLoaded() to extension_is_loaded() 2017-03-14 14:08:39 +01:00
Erik Nordström
aa51e221f3 Break up timescaledb.c into separate source files.
This patch refactors the source code so that a bunch of unrelated code
for the planner, process utilities and transaction management, which
was previously located in the common file timescaledb.c, is now broken
up into separate source files.
2017-03-14 13:50:08 +01:00
Erik Nordström
d1ad3afd49 Perform native scans for chunks (replicas)
Previously, chunk replicas were retreived with an SPI query. Now, all
catalog items are retrieved with native scans, with the exception of
newly created chunks.

This commit also refactors the chunk (replica) cache, removing some
data structures that were duplicating information. Now chunks are
cached by their ID (including their replicas) instead of just the
set of replicas. This removes the need for additional data structures,
such as the replica set which looked like a chunk minus time info,
and the cache entry wrapper struct. Another upside is that chunks
can be retrieved from the cache directly by ID.
2017-03-10 17:28:49 +01:00
Matvey Arye
32c45b75b2 formatting with pgindent 2017-03-06 15:20:00 -05:00
Rob Kiefer
ee3ad4678d Rename iobeamdb to TimescaleDB 2017-03-06 11:06:49 -05:00
Matvey Arye
4d4ac78ef5 cleanup 2017-03-05 10:13:45 -05:00
Matvey Arye
2404940315 getting rid of move_plan in cache. creating the plan caused a lock to be taken on the chunk table -- a lock which lead to a deadlock 2017-03-03 10:10:14 -05:00
Matvey Arye
64e8ec1877 Ordering inserts to avoid deadlocks 2017-03-03 10:10:14 -05:00
Matvey Arye
67ad21ee36 Cache hypertable metadata information for faster inserts.
Add caches for hypertable metadata to make it faster to map
INSERT rows to the chunk they should go into.
2017-03-02 12:24:53 +01:00