General Study Flashcards
Explain the Pub/Sub Model (4 Features)
- Decoupling
- Messaging Server
- Asynchronous Communication
- Pub/Sub Model
What does the use of a queue model do to a Publish Subscribe Model
The use of a strict queue means that only one user will be able to read the message
Give an example of a publisher subscribe model.
Youtube Subscribers
What is a Local Conceptual Schema
A fragment of the global conceptual schema stored locally on site. Has its own local physical schema.
Advantages of Distribute + Replicate
Performance, Fault Tolerance, Scale Up, Application Related Aspects
When not to replicate
- When there is Low Replication Transparency
- When there is Data Consistency Issues
What is Update Propagation Protocol?
Set of rules for how changes/updates to data are propagated.
Synchronous/Primary Copy UPP:
Primary Copy
On Read: Read Locally and Return to User
On Write: Write locally, multicast to replicas
On Commit Req: Run 2PC Coordinator
On Abort: Abort + Inform other sites.
Secondary Copy
On Read: Read Locally
On Write from Client: Refuse or forward to primary.
On Write from Prim.: Write locally, multicast to replicas
On Commit Req: Commit locally
Participant of 2PC on primary
Synchronous/Primary Copy Advantages
- Updates don’t have to be coordinated
- No inconsistencies or Deadlocks
Synchronous/Primary Copy Disadvantages
- Long response time
- Useful only with few updates
- Local copies almost useless
- Not used in practise
Synchronous/Update Everywhere Advantages:
- No inconsistencies
- Elegant (Updates applied uniformly)
- Data Consistency
- Fault Tolerance
Asynchronous/Primary Copy
Primary Copy
On Read: Read Locally and Return to User
On Write: Write locally, return to user
On Commit/Abort: Terminate locally
After Commit: Multicast changed objects in single array.
Secondary Copy
On Read: Read Locally
On Write from Client: Refuse or forward to primary.
On Message from Prim.: Install changes in order
On Commit/Abort: Commit locally
Only local deadlocks
Asych/Primary Copy Advantages
- No coordination needed
- Short response time
- Good Performance
Asynch/Primary Copy Disadvantages
- Local Copies not updates
- Inconsistencies
- Limited Fault Tolerance
Asynch/Update Everywhere
Primary Copy
On Read: Read Locally and Return to User
On Write: Write locally, return to user
On Commit/Abort: Terminate locally
On msg from other site: Detect Conflicts
After Commit: Multicast changed objects in single array.
Secondary Copy
On Read: Read Locally
On Write from Client: Refuse or forward to primary.
On Message from Prim.: Install changes in order
On Commit/Abort: Commit locally
Only local deadlocks
Explain ROWA
Read One, Write All. Replication strategy where each site keeps local data copy and rules govern how operations are handled.
Concepts:
- Each Site uses 2PL
- Read Ops performed locally
- Write Ops performed at all sites
Reconciliation patterns
1) Latest Update Wins (Most recent update preferred when conflict occurs)
2) Site Priority (Prioritize Updates from HQ)
3) Largest Value (Prioritize Largest transaction)
Ad-hoc Reconciliation strategies
1) Identify Changes and try combine them
2) Analyze and eliminate unimportant transactions
3) Create your own priority schemas
Replication Protocols to deal with replications with failures
Site Failures -> Use ROWAA
Network/Comm errors -> Use Quorums
Quorum
Needs to reach a certain threshold of successful responses before considering a transaction committed.
ROWAA (Primary Site)
Read -> Read any copy, if timed out read another copy
Write -> Send write(x) to all copies. If a site rejects, abort. All sites that don’t respond are missing writes.
Validation -> To commit a transaction. Check if missing writes are still down, if no then abort. Also check if available sites are still available, if no then abort.
ROWAA (Update Everywhere)
Read -> Read any copy from available sites
Update -> Update any copy from available sites
Modify -> Run a special atomic transaction at all sites: Make sure no concurrent views exist. Make sure sites are of the highest version.
Recovery -> Get missed updates from active nodes.
What does NOTIFY do?
Raises notification event on certain cannel to clients that subscribed. If no session is listening, notifications are lost.
Notification Structure
Channel, Process ID, Payload
Notification Syntax
Notify Channel [, msg_payload]
OR
pg_notify(chn::text, msg::text);
What does Listen do
Registers the spawning session to a notification channel
Listen Operations:
- When notification raised, registered sessions are notified
- Sessions can issue ‘unlisten’ to server
- Registrations automatically UNLISTENED when session ends.
Listen Syntax
LISTEN channel
UNLISTEN channel
or
pg_listen conn notifyName
Timing of Producer sending messages
Calling Notify
- If raised during transaction, queue notification until after commit.
- If transaction rolled back, notification never delivered
Timing of Consumer seeing messages
Calling Listen
-If called during transaction, no access until local session transaction commits or rolls back.
- The channel is accessed after the local session terminates.
What is the Notify Listen Model
Implementation mechanism of Pub/Sub Models. Notify and Listen are part of dblink extension (non-standard SQL).
Generate Json from a table
COPY(SELECT row_to_json(r) FROM (SELECT * FROM scott.dept r)) to ‘filename.json’;
Generate XML from data
SELECT table_to_xml(‘scott.dept’, true, false”);
SELECT query_to_xml(‘scott.dept’, true, false”);
Show how XPATH is used
SELECT data FROM test_table WHERE CAST (xpath(‘||root|s_node*|text()’,data) as text[]) = ‘{a_value}’;
Get a resource using CURL
curl
–insecure
–request
GET “resource url&key”
What is REST (Just definition)
Representation State Transfer is an architecture used for interfacing with web services. Any API following REST principles is considered RESTful.
What are the Principles of REST (There are 6)
- Client Server Architecture
- Stateless Operation (receive enough info to understand msg in isolation)
- Resource Caching (Requests may be answered through a cache)
- Uniform Interface (Server announces available actions and resources for ease)
-Layered System (Client can’t tell if it’s connected directly or through middleman) - Code On Demand (optional; clients can send executable code)
What is an idempotent operation
An operation that can be carried out multiple times while leaving the server in the same state ex. x=1.
Fault tolerant. Safe as doesn’t alter state.