




























































































Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!





























































































The solution we want need to be effectively and efficiently. Where:
A distributed database it is a system in which data are physically distributed across multiple servers but are managed in such a way as to appear as a single logical database to the user or application. Is a way to organize data. Since we must manage a huge amount of data, most of the time we need to spread the data in different places, but the final user must not have the perception of this. There are different paradigms for data distribution:
(On-Line Transaction Processing): is a type of paradigm use for optimizing management and reliable transaction on database. Is specialized on the management of hundreds or even thousands of transactions per second. Is useful for manage everyday activities but not for making decision and prediction. Il paradigma OLTP è orientato alle operazioni quotidiane. Immagina il database di un e-commerce o di una banca: ogni volta che compri un libro o prelevi al bancomat, stai eseguendo una transazione OLTP. ● Obiettivo: Gestire un volume enorme di piccole transazioni rapide. ● Operazioni tipiche: INSERT, UPDATE, DELETE.
(On-Line Analytical Processing): is specially use for data analysis. Operate on data warehouse servers, specialized on the management of data for decision support system. Il paradigma OLAP è orientato all'analisi e alla Business Intelligence. Qui non ci interessano i singoli dettagli della transazione di un secondo fa, ma cerchiamo trend e aggregazioni su milioni di record storici. ● Obiettivo: Fornire risposte a query complesse per il supporto alle decisioni. ● Operazioni tipiche: SELECT massicce con aggregazioni (SUM, AVG, COUNT). Is useful for extract information for read only but, due to the large amount of data, in can takes a lot of time. Servers typically include both OLTP and OLAP functionality, but OLTP and OLAP have opposing needs. OLTP handles many small, fast transactions that continuously modify data, while OLAP runs complex analytical queries on large volumes of historical data. Running them together can cause OLAP queries to slow down OLTP transactions, which require very fast response times. For this reason, in most modern systems the two workloads are kept separate — operational data lives in the OLTP database and is periodically transferred via ETL to a dedicated OLAP system, which is exactly the role of the Data Warehouse. 1.2 PROPERTIES OF DISTRIBUTED SYSTEMS
Is the possibility to transporting programs from an environment to another, without the necessity of transcribe it. Is established at compile time and is facilitated by language standards.
Is the ability of interacting among heterogenous system. Also this one is established at compile time and is facilitated by standard protocols for data access (e.g., Database Connectivity (ODBC) e X-Open Distributed Transaction Processing (DTP)). When I use data warehouses, I must manage different heterogeneous servers so I need data that can communicate each other. 1.3 CLIENT – SERVER ARCHITECTURES
management) and have considerable disk capacity (to store the whole database).
The distribution of activities is depending on the resources of the client and the server. In thin client solution I can have a bottleneck on server side instead, in the fat client solution I can have a bottleneck on client side. This because in a thin client solution, most of the processing happens on the server side, so the bottleneck is on the server side — if many clients send requests simultaneously, the server can become overloaded, and in a fat client solution, more processing is moved to the client side, which relieves the server. However, the bottleneck can shift to the client side if the client machine doesn't have enough resources to handle the workload locally. Fat Clients: ✓ More efficient for users ✓ Provide higher system scalability ✗ More complex and harder to manage ✗ Client software is more error prone and depends on the client machine and its OS Thin Clients: ✓ Easier to manage ✗ Potential bottleneck on the server side The general trend now a days move computation to the client side. Siamo passati dai Mainframe (Thin Client puri), ai PC degli anni '90 (Fat Client puri), al Web 2.0 (Thin Client/Browser), e ora verso le Single Page Applications (SPA) e le App Mobile, che sono essenzialmente dei nuovi "Fat Client": il codice viene scaricato una volta e gira localmente, comunicando con il server solo per lo stretto necessario. The generalization of this concept is the multi – tiered architectures
A server may act as a client. Different programs in the processing level reside on different servers. Definition of distributed databases: System of databases where at least one client interacts with more servers for the execution of an application.
The pros of those types of DB are: Respond to applications requirements o organizations have a distributed structure, o data distribution permits the management of data where they are generated and used. Flexibility and modularity o can be configured with continuous additions and modifications of components. Reliability o can react to failures reducing performance instead of stopping operability. Un punto cruciale è che, sebbene un client interagisca con più server, l'utente non dovrebbe accorgersene. Questo si chiama Trasparenza della Distribuzione: il database distribuito deve apparire all'utente come un singolo database locale, anche se i pezzi (frammenti) sono sparsi per il mondo Considering the technological aspect there are two different kinds of involved DBMSs:
The distributed database can be considered, from an abstract point of view, as a single database. It should be designed in such a way to have applications that are executed on a single server, minimizing the need of interaction and the need of data exchange.
The data fragmentation is the concept of adopts algebraic operations on a relation R to divide it into fragments R1, …, Rn (also relations). There are two different types of fragmentation. Horizontal fragmentation
Allocation can be:
There are 4 different levels of transparency that describe how much the programmer needs to know
asking multiple people to search for something at the same time instead of having them search one at a time.
instead of searching across all of them.
Ad esempio, se so che i dati dei fornitori di Milano si trovano nel frammento SUPPLIER1, eseguo la query solo su quello, invece di cercare in tutti i frammenti. Tuttavia, questo approccio comporta un importante compromesso: da un lato aumenta l'efficienza, poiché si evita di eseguire query su frammenti non necessari, dall'altro riduce la flessibilità, poiché il codice diventa dipendente dalla struttura specifica dei frammenti — se la frammentazione cambia, il codice deve essere riscritto. SUPPLIER (Snum, Name, City) La tabella viene divisa in pezzi (frammenti) in base a una condizione sulle righe: Horizontal fragmentation → SUPPLIER 1 = σ city = “Milan” (SUPPLIER) → solo i fornitori di Milano SUPPLIER 2 = σ city = “Rome” (SUPPLIER) I frammenti vengono distribuiti su più server, dopo essere stati divisi con una certa logica, vengono allocati, in questo caso anche con replicazione, infatti SUPPLEIER2 viene messo in roma1 e roma2:
Allocation of Horizontal fragmentation → [email protected] [email protected] [email protected] L’idea è che l’utente non deve sapere che la tabella è divisa, dove si trovano i dati e che esistono copie.
Il programmatore scrive codice come se lavorasse su un database locale standard. Il sistema si occupa di tradurre la richiesta logica in operazioni fisiche sui vari nodi. procedure Query1(:snum,:name); select Name into :name from Supplier -- usa il nome della tabella globale where Snum = :snum; end procedure;
procedure Query2(:snum,:name); select Name into :name from Supplier where Snum = :snum; if :empty then select Name into :name from Supplier where Snum = :snum; end procedure;
needs to know the structure of fragments needs to know the allocation procedure Query3(:snum,:name); select Name into :name from [email protected] where Snum = :snum
each DBMS accepts its own SQL dialect: the system is heterogeneous and the DBMSs do not support a common interoperability standard
SHOP (ID , Name , Kind , Tel , City , ID Warehouse) WAREHOUSE (ID , Street , City , Tel) SHOP is split in 3 fragments based on the kind of shop (clothes , shoes , bath) allocated at three coordination centres, one for each kind of shop in Cagliari , Siena , Bari respectively WAREHOUSEis split in4 fragments based on the city where warehouses are located: Milan , Florence , Rome , Venice allocated at the three corresponding shipment centres in the same cities. Fragments: SHOPC: σ kind = "clothes" SHOP @ Cagliari SHOPS: σ kind = "Shoes" SHOP @ Siena
1.5 TRANSACTION CLASSIFICATION:
complexity levels
numero arbitrario di query SQL. Quindi viene fatta una sola domanda a un certo DBMS (es. SELECT certe informazioni di un certo DB)
All the commands are addressed to a single remote DBMS Each transaction writes one DBMS only Una singola transazione riguarda un unico DBMS ed è possibile anche modificarlo oltre a leggerlo (quindi con SELCT, INSERT, …)
delete, update) addressed to an arbitrary number of remote DBMSs Each SQL command refers to a single DBMS → quindi ogni comando fa riferimento a un unico DBMS Each transaction can update different DBMSs requires two-phase-commit protocol La transazione "parla" con più server, ma ogni singolo comando SQL è indirizzato a un server specifico.
commands (select, insert, delete, update) addressed to an arbitrary number of remote DBMSs Each command can refer to any DBMS Requires a distributed query optimizer
contemporaneamente. quindi il lv di complessità di questi tipi di transizioni cresce. SELECT A1,A FROM T1 JOIN T2 ON T1.k = T2.k WHERE A3 = v And A4 = x È necessario effettuare operazioni di ottimizzazioni per migliorare le connessione e il recupero dei dati. per costruire una transizione, si usa begin transaction update CC set Balance = Balance - 100 where CCNum = ʻ354ʼ ; update CC set Balance = Balance + 100 where CCNum = ʻ1487ʼ ; commit; end transaction
1.6 PROPERTIES OF TRANSACTION Le proprietà delle transazioni sono: ACID: Transactions should satisfy ACID properties 1.6. 1 ATOMICTY Atomicity: la transazione è unità atomica, non può lasciare un database in uno stato intermediario, se
The effects of a transaction that executed commit should not be lost The system should guarantee persistency of data even in case of failures and malfunctioning Data distribution does not affect, among ACID properties of transactions consistency: integrity constraints describe only local properties • it is a limit of current DBMS technology persistency: each system guarantees persistency to locally stored data • local recovery (log, checkpoint, dump) mechanisms
Data distribution affects
Dipende, se sono considerate come transazioni complete, Se lavorano in modo seriale e non parallelo, significa che sono localmente serializzabili e globalmente non serializzabili. L'illusione della serializzabilità locale. Spiega che un sistema distribuito può sembrare "in ordine" se guardi i singoli server, ma essere nel caos più totale se guardi l'intero sistema (Global Serializability). Il Paradosso: Locale vs Globale ● Locally Serializable: Sui singoli server (S1 e S2), le operazioni avvengono in modo ordinato (seriale). Ogni server pensa di fare il suo lavoro correttamente. ● Globally Non-Serializable: Se metti insieme i pezzi, l'ordine globale è impossibile da determinare. Si è creato un conflitto logico che rompe la coerenza dei dati. Local serializability does not guarantee global serializability Example S1 : r11(x) w11(x) r21(x) w21(x) S2 : r22(y) w22(y) r12(y) w12(y) Locally serializable (serial) Globally non serializable →Global serializability requires the presence of a serial schedule S equivalent to all the local schedules Si resulting at each node
Problema del Concurrency Control Distribuito: come garantire che l'esecuzione di transazioni su nodi diversi equivalga a un'esecuzione "una dopo l'altra" (seriale), evitando il caos visto nell'esempio precedente. Global serializability: properties Conflict-serializable global schedule → guaranteed if each scheduler uses strict 2PL and executes atomic commit when all the sub-transactions at the different nodes have all the resources Serial global schedule → guaranteed if each distributed transaction acquires a single timestamp and uses it in all its requests to all the schedulers that perform concurrency control based on timestamp - requires the assignment of a global timestamp ha un ordine specifico e si deve tenere con il TIMESTAMP il problema è la SINCRONIZZAZIONE nei sistemi distribuiti Garantire la Serializzabilità Globale (CSR) Per evitare cicli nel grafo dei conflitti, il sistema deve imporre una disciplina comune a tutti i nodi. ● Strict 2PL (Two-Phase Locking): È il metodo più usato. Ogni nodo blocca le risorse (lock). La chiave qui è l'Atomic Commit: i lock vengono rilasciati solo dopo che tutti i nodi hanno confermato di aver finito. Questo assicura che l'ordine dei conflitti sia identico ovunque. ● Global Timestamp: Ogni transazione riceve un "biglietto" con l'ora di inizio (timestamp) univoco per tutto il sistema. Se T1 ha un timestamp minore di T2, tutti i server devono far passare T1 per prima. Il problema qui è la sincronizzazione dei clock tra i server (molto difficile).
le stesse cose e lasciano il database nello stesso stato finale.
*questa situazione è cross: sono basate su azioni e parti che non hanno ancora avuto il commit dall’azione prima quindi bisogna farli in ordine
1.8 LOGICAL CLOCKS I Logical Clock (Orologi Logici) servono a risolvere un problema enorme dei sistemi distribuiti: l'impossibilità di avere un'ora esatta condivisa. Need to assign timestamps that reflect precedence among events in a distributed system
altrimenti non è necessario. Happend Before (lamport clock and vector clock) a → b si usa la → per simboleggiare che operazione avviene prima, rispetto all’altra a → b means that all transactions agree that first a occurs and then b occurs a and b are in the same transaction and a occurs before b
relationship
How do we maintain a global view on the system’s behavior that is consistent with the happened-before relationship? Attach a timestamp C(e) to each event e s.t.:
VECTOR clock: riesce a catturare la precedenza causale, sempre formalizzato da Lamport, ogni processo Pi ha un vettore VCi[1, …n] che ha o VCi [i] is the number of events that have occurred at Pi o VCi [j] is the number of events that Pi knows have occurred at P I Vector Clock sono l'evoluzione degli orologi di Lamport. Mentre Lamport usa un singolo numero, qui ogni processo mantiene un array (vettore) di n contatori, dove n è il numero di processi nel sistema. Ecco come funzionano "in breve" e perché risolvono il limite di Lamport:
Ogni processo Pi ha un vettore VCi. ● Evento Locale: Quando Pi esegue un evento, incrementa solo la propria posizione nel vettore: VC_i[i] = VC_i[i] + 1 ● Invio: Pi invia il suo intero vettore insieme al messaggio. ● Ricezione: Quando Pi riceve un messaggio con il vettore VCmsg, aggiorna ogni elemento del suo vettore prendendo il massimo: (e poi incrementa la propria posizione VCi[i] per l'evento di ricezione).
A differenza di Lamport, guardando due vettori puoi capire se due eventi sono causalmente legati o concorrenti: ● Causalità (a → b): L'evento a precede b solo se ogni elemento del vettore di a è minore o uguale a quello di b (VC(a)[j] \le VC(b)[j] per ogni j) e almeno uno è strettamente minore. Significa che l'informazione di a è "fluita" fino a b. ● Concorrenza (a \ b): Se in alcune posizioni è maggiore il vettore di a e in altre quello di b, allora gli eventi sono concorrenti. Nessuno dei due sapeva dell'altro quando è avvenuto.
Immagina due processi P1 e P2: ● P1 ha [1, 0] ● P2 ha [0, 1] Nessun vettore è "più grande" dell'altro. Il sistema capisce immediatamente che questi due eventi sono avvenuti nello stesso momento logico senza influenzarsi. In un database distribuito, questo attiverebbe una gestione dei conflitti (es. "Write Conflict"), cosa che l'orologio di Lamport standard non riuscirebbe a fare con la stessa precisione. Vector clocks (2)
Ogni volta che il processo Pi fa qualcosa (scrive un dato, fa un calcolo o si prepara a inviare/ricevere un messaggio), deve aggiornare la sua posizione nel vettore. ● Significato: "Ho appena vissuto un nuovo evento nel mio nodo". ● Esempio: Se il processo è P1 e il suo vettore è [0, 0, 0], dopo un evento diventa [1, 0, 0].
per risolvere questo problema di deadlock, ci possono esere 2 modi:
2.1 ONE PHASE COMMIT
Starting with a transaction t that is divided in t1,t2,t3,t4,… running in different nodes 𝑡ଵ @𝑛ଵ 𝑡ଶ @𝑛ଶ
𝑡ସ @𝑛ସ → x has a problem One of them take a particular role, so like a coordinator of the protocol, so one node, is more powerful than the other.
the coordinator tells the other what to do: need to enforce or not something. Suppose: Node 𝑛ସhas a problem (like violation, crash, …)so it cannot complete its part, so one participant
This protocol is theoretically but not used in concrete, is a simply way to understand the problem. It’s useful only to understand the problem because: The coordinator has too little information, also there is no agreement phase, and failures are not handled safely. 2.2 TWO-PHASE COMMIT The Two-Phase Commit Protocol is a protocol used to make sure that a distributed transaction behaves like one. So is a combination with 2 different phases. Sort of protocol that managing Need to agreement with the participant and the coordinator.
The commit/abort decision is taken by the parties and registered by a coordinator, distinguishing between:
È necessario registrare tutto su disco per poter riprendere correttamente dopo un errore quindi si usano i Log per poter capire cosa succede effetivamente durante una transazione distribuita, nel caso in cui ci sia un crash infatti, bisogna capire cosa è successo prima del crash per permettere al sistema di ripartire. Ci sono 2 tipi di log, uno per il TM e uno per il RM. Logs are important because manage also the failure, and when nodes suffer failure, the other nodes
which phase I’m.
prepare → Contains the identity the list of all the RM processes (node and process identifier). global commit or global abort → Describes the global decision and is final when it is recorded in the log. complete → Records the end of the 2PC protocol.
Ready → it means that RM is ready to commit and it’s written only when the node is in a secure state → indicates the availability to participate in the 2PC protocol, and to contribute to the final decision → can be written only when the RM is in a reliable state, that is, when it has the lock on all the resources that need to be written → reports the (node and process) identifier of the TM *begin, insert, delete, and update → operation of the local transaction Il momento in cui un Resource Manager (RM) passa da uno stato “autonomo” a uno “vincolato” dalla decisione del Transaction Manager (TM). When a RM declares that it is ready for a transaction, it loses its own autonomy and is subject to the decision of the TM, because has just execute the transaction and has guaranteed that can do commit after that also after a crash