20 Commits

Author SHA1 Message Date
Joshua Lockerman
4e1e15f079 Add reorder command
New cluster-like command which writes to a new index than swaps,
much like is done for the data table, and only acquires
exclusive locks for said swap. This trades off disk usage for
lower contention: we hold locks for a much lower period of time,
allowing reads to work concurrently, but we have both the old
and new versions of the table existing at once, approximately
doubling storage usage while reorder is running.

Currently only works on chunks.
2019-01-02 15:43:48 -05:00
Sven Klemm
92586d8fc9 Fix typos in comments 2018-12-31 18:36:05 +01:00
Sven Klemm
b1378449bc Remove unused functions
Remove the following unused functions:
ts_cache_switch_to_memory_context
ts_chunk_free
ts_chunk_exists
ts_chunk_index_delete_children_of
ts_chunk_index_delete_by_hypertable_id
ts_hypertable_scan_relid
ts_tablespaces_clear
ts_tablespaces_delete
2018-12-18 10:35:04 +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
Joshua Lockerman
d8e41ddaba Add Apache License header to all C files 2018-10-29 13:28:19 -04:00
Erik Nordström
3c28f65f44 Release cache pin memory
Cache pins are allocated on the CacheMemoryContext in order to survive
subtransactions, and, optionally, main transactions (in case of, e.g.,
clustering or vaccuming). However, cache pins that are released also
needs to free memory on the CacheMemoryContext in order to avoid
leaking memory in a session.

This change ensures cache pin memory is freed when a cache pin is
released. It also allocates cache pins on a separate memory context,
which is a child of the CacheMemoryContext. This separate memory
context makes it easier to track the memory used by cache pins and
also release it when necessary.
2018-07-10 10:15:30 +02:00
Erik Nordström
2e1f3b9fd0 Improve memory allocation during cache lookups
Previously, cache lookups were run on the cache's memory
context. While simple, this risked allocating transient (work) data on
that memory context, e.g., when scanning for new cache data during
cache misses.

This change makes scan functions take a memory context, which the
found data should be allocated on. All other data is allocated on the
current memory (typically the transaction's memory context). With this
functionality, a cache can pass its memory context to the scan, thus
avoiding taking on unnecessary memory allocations.
2018-06-22 16:45:07 +02:00
Matvey Arye
744ca0920c Fix Cache Pinning for Subtxns
Previously, all Subtxn aborts released all cache pins. This is
wrong because that can release pins that are still in use by
higher-level subtxns and top-level txns. Now, we release only
pins corresponding to the appropriate subtxn. That means that we
now track the subtxn a pin was created in.
2018-03-15 11:52:51 -04:00
Matvey Arye
b31c8dbd1e Address coverity complaints 2018-02-16 15:58:44 -05:00
Matvey Arye
78d36b52d4 Handle subtxn for cache pinning
This commit adds logic for cache pinning to handle subtxn. It also makes
it easier to find cache pinning leaks. Finally, it fixes handling of
cross-commit operations like VACUUM and CLUSTER. Previously, such
operations incorrectly released that cache pin on the first commit
even though the object was used after that.
2018-01-11 09:35:37 -05:00
Erik Nordström
55bfdf753a Release all cache pins when a transaction ends
Currently, if a transaction ends (normally or abnormally) while a
cache is pinned, that cache will never be released, leading to a
memory leak. This change ensures that all taken cache pins are
released when a transaction ends by registering all pins in a list and
cleaning it up in a transaction end callback. This makes the use of
cache_release() optional. However, timely calls to cache_release() is
still encouraged since it is better to release memory as soon as
possible during long-running transactions.
2017-08-09 13:53:03 +02: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
Matvey Arye
14ac892c88 Fix possible segfault
Previously cache_destroy NULLed out memory in a MemoryContext that it
just deleted. This could cause a segfault and is fixed by this PR.
2017-06-27 09:27:17 -04:00
Robin Thomas
7b2097a975 ran pgindent successfully with local typedefs; ended up correcting
several code style discrepancies from master.
2017-04-29 18:32:07 -04:00
Erik Nordström
5c2bef47f1 Use a cache's own memory context on cache updates
In case new allocations are made during a cache entry update, we
should use the cache's internal memory context to ensure that new data
is allocated and freed in a way consistent with the rest of the cache.
2017-03-24 08:16:36 +01:00
Erik Nordström
89692c9761 Add cache statistics and do minor cleanup
Track statistics for cache hits and misses in the cache module.
Currently not exposed to SQL, but might be useful for internal
debugging.
2017-03-22 09:57:44 +01:00
Matvey Arye
32c45b75b2 formatting with pgindent 2017-03-06 15:20:00 -05:00
Matvey Arye
4d4ac78ef5 cleanup 2017-03-05 10:13:45 -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