Merge branch 'develop' of github.com:matrix-org/synapse into erikj/sync

pull/536/head
Erik Johnston 2016-01-28 14:46:08 +00:00
commit 19fd425928
4 changed files with 20 additions and 28 deletions

View File

@ -52,7 +52,7 @@ RUN_POSTGRES=""
for port in $(($PORT_BASE + 1)) $(($PORT_BASE + 2)); do for port in $(($PORT_BASE + 1)) $(($PORT_BASE + 2)); do
if psql synapse_jenkins_$port <<< ""; then if psql synapse_jenkins_$port <<< ""; then
RUN_POSTGRES=$RUN_POSTGRES:$port RUN_POSTGRES="$RUN_POSTGRES:$port"
cat > localhost-$port/database.yaml << EOF cat > localhost-$port/database.yaml << EOF
name: psycopg2 name: psycopg2
args: args:
@ -62,7 +62,7 @@ EOF
done done
# Run if both postgresql databases exist # Run if both postgresql databases exist
if test $RUN_POSTGRES = ":$(($PORT_BASE + 1)):$(($PORT_BASE + 2))"; then if test "$RUN_POSTGRES" = ":$(($PORT_BASE + 1)):$(($PORT_BASE + 2))"; then
echo >&2 "Running sytest with PostgreSQL"; echo >&2 "Running sytest with PostgreSQL";
$TOX_BIN/pip install psycopg2 $TOX_BIN/pip install psycopg2
./run-tests.pl --coverage -O tap --synapse-directory $WORKSPACE \ ./run-tests.pl --coverage -O tap --synapse-directory $WORKSPACE \

View File

@ -255,12 +255,13 @@ class SynapseHomeServer(HomeServer):
quit_with_error(e.message) quit_with_error(e.message)
def get_db_conn(self): def get_db_conn(self):
db_conn = self.database_engine.module.connect( # Any param beginning with cp_ is a parameter for adbapi, and should
**{ # not be passed to the database engine.
k: v for k, v in self.db_config.get("args", {}).items() db_params = {
if not k.startswith("cp_") k: v for k, v in self.db_config.get("args", {}).items()
} if not k.startswith("cp_")
) }
db_conn = self.database_engine.module.connect(**db_params)
self.database_engine.on_new_connection(db_conn) self.database_engine.on_new_connection(db_conn)
return db_conn return db_conn

View File

@ -28,7 +28,7 @@ from synapse.notifier import Notifier
from synapse.api.auth import Auth from synapse.api.auth import Auth
from synapse.handlers import Handlers from synapse.handlers import Handlers
from synapse.state import StateHandler from synapse.state import StateHandler
from synapse.storage import get_datastore from synapse.storage import DataStore
from synapse.util import Clock from synapse.util import Clock
from synapse.util.distributor import Distributor from synapse.util.distributor import Distributor
from synapse.streams.events import EventSources from synapse.streams.events import EventSources
@ -117,7 +117,7 @@ class HomeServer(object):
def setup(self): def setup(self):
logger.info("Setting up.") logger.info("Setting up.")
self.datastore = get_datastore(self) self.datastore = DataStore(self.get_db_conn(), self)
logger.info("Finished setting up.") logger.info("Finished setting up.")
def get_ip_from_request(self, request): def get_ip_from_request(self, request):

View File

@ -61,22 +61,6 @@ logger = logging.getLogger(__name__)
LAST_SEEN_GRANULARITY = 120*1000 LAST_SEEN_GRANULARITY = 120*1000
def get_datastore(hs):
logger.info("getting called!")
conn = hs.get_db_conn()
try:
cur = conn.cursor()
cur.execute("SELECT MIN(stream_ordering) FROM events",)
rows = cur.fetchall()
min_token = rows[0][0] if rows and rows[0] and rows[0][0] else -1
min_token = min(min_token, -1)
return DataStore(conn, hs, min_token)
finally:
conn.close()
class DataStore(RoomMemberStore, RoomStore, class DataStore(RoomMemberStore, RoomStore,
RegistrationStore, StreamStore, ProfileStore, RegistrationStore, StreamStore, ProfileStore,
PresenceStore, TransactionStore, PresenceStore, TransactionStore,
@ -98,10 +82,17 @@ class DataStore(RoomMemberStore, RoomStore,
EventPushActionsStore EventPushActionsStore
): ):
def __init__(self, db_conn, hs, min_stream_token): def __init__(self, db_conn, hs):
self.hs = hs self.hs = hs
self.min_stream_token = min_stream_token cur = db_conn.cursor()
try:
cur.execute("SELECT MIN(stream_ordering) FROM events",)
rows = cur.fetchall()
self.min_stream_token = rows[0][0] if rows and rows[0] and rows[0][0] else -1
self.min_stream_token = min(self.min_stream_token, -1)
finally:
cur.close()
self.client_ip_last_seen = Cache( self.client_ip_last_seen = Cache(
name="client_ip_last_seen", name="client_ip_last_seen",