Docsity

Information Management (Sara Foresti), Appunti di Information Technology Management

Toggle sidebar
bg1
Information management
0. INTRODUCTION
The information management is essential because we live in a society that generate a
huge
amount
of heterogenous
data
that can be used to extract information for decision making.
There are
different ways for organizing data
, like: relational data, file collections and noSQL data.
The solution we want need to be effectively and efficiently. Where:
-
Effectively
: refers to
what
is done with data — being able to perform useful operations such
as storing, managing, processing, analyzing, extracting, combining, representing, and summarizing
information, ultimately providing answers to questions.
-
Efficiently
: refers to
how it is done
— not necessarily through a traditional relational database
system, but through solutions that, for example, offer visual representations of data in the most
useful way for decision-makers.
1. DISTRIBUTED DATABASES
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:
- Client – server architectures: typical and base distributed architecture that
separate the database
server and client
.
- Distributed databases: where at least
one client interacts with multiple servers
to run an application.
Data is spread across servers through fragmentation (horizontal or vertical) and can be redundant or
nonredundant. The goal is to make everything appear as a single logical database despite the physical
distribution.
- Parallel databases: multiple storage devices and processors that work simultaneously to improve
performance. Unlike distributed databases, the focus here is on speed through parallelism rather than
geographic distribution of data.
- Replicate databases: kind of distribution, same data is physically stored on multiple servers. This
improves availability and fault tolerance — if one server fails, the data remains accessible from another.
The main challenge is keeping all copies consistent and synchronized. Of course, if the entire building shut
down the access to data is compromise.
- Data warehouses: the main difference forms the others is that, in this case, we must manage a bigger
amount of data. Are servers specialized for decision support, operating in OLAP mode (On-Line
Analytical Processing). They store large amounts of historical data used for analysis and decision making,
as opposed to OLTP systems which handle everyday transactional operations. They support techniques like
data mining and data visualization.
1.1 THERE ARE TWO DIFFERENT KINDS OF SYSTEM PARADIGM:
1.1.1. OLTP
(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.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Anteprima parziale del testo

Scarica Information Management (Sara Foresti) e più Appunti in PDF di Information Technology Management solo su Docsity!

Information management

0. INTRODUCTION

The information management is essential because we live in a society that generate a huge amount

of heterogenous data that can be used to extract information for decision making.

There are different ways for organizing data, like: relational data, file collections and noSQL data.

The solution we want need to be effectively and efficiently. Where:

  • Effectively: refers to what is done with data — being able to perform useful operations such as storing, managing, processing, analyzing, extracting, combining, representing, and summarizing information, ultimately providing answers to questions.
  • Efficiently: refers to how it is done — not necessarily through a traditional relational database system, but through solutions that, for example, offer visual representations of data in the most useful way for decision-makers.

1. DISTRIBUTED DATABASES

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:

  • Client – server architectures: typical and base distributed architecture that separate the database

server and client.

  • Distributed databases: where at least one client interacts with multiple servers to run an application. Data is spread across servers through fragmentation (horizontal or vertical) and can be redundant or nonredundant. The goal is to make everything appear as a single logical database despite the physical distribution.
  • Parallel databases: multiple storage devices and processors that work simultaneously to improve performance. Unlike distributed databases, the focus here is on speed through parallelism rather than geographic distribution of data.
  • Replicate databases: kind of distribution, same data is physically stored on multiple servers. This improves availability and fault tolerance — if one server fails, the data remains accessible from another. The main challenge is keeping all copies consistent and synchronized. Of course, if the entire building shut down the access to data is compromise.
  • Data warehouses: the main difference forms the others is that, in this case, we must manage a bigger amount of data. Are servers specialized for decision support, operating in OLAP mode (On-Line Analytical Processing). They store large amounts of historical data used for analysis and decision making, as opposed to OLTP systems which handle everyday transactional operations. They support techniques like data mining and data visualization.

1.1 THERE ARE TWO DIFFERENT KINDS OF SYSTEM PARADIGM:

1.1.1. OLTP

(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.

1.1.2. OLAP

(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

1.2.1 PORTABILITY

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.

1.2.2 INTEROPERABILITY

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

Interacting software processes are divided between client ( requests services) and server ( provides

services):

  • Requires a precise definition of service interface, listing precisely the services offered by the server.
  • The client has an active role (makes the request).
  • The server has a reactive role (replies).
  • Usually, a client process requests a few services in a sequence to one or more server processes.
  • Usually, a server process replies to multiple requests by different client processes. Client and server are both application: the client application request the service instead the server application provide the service. The machine acting as client should
  • be adequate for interacting with the final user.
  • Support productivity tools (email, word processing, Internet access, and workflow management).

The machine acting as server should have considerable memory capacity (to support buffer

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

1.3.2 MULTI – TIERED ARCHITECTURES

A single server is replaced by multiple servers running on different machines.

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:

  • homogeneous DDB (all servers use the same DBMS)
  • and heterogeneous DDB (the servers use different DBMSs). And, we can have different kind of network use: LAN and WAN Tutti i nodi utilizzano lo stesso software (es. tutti Oracle o tutti PostgreSQL). ● Vantaggio: È molto facile farli comunicare tra loro. Usano lo stesso linguaggio, gli stessi tipi di dati e gli stessi protocolli di transazione. ● Tabella: Come vedi, si usano in LAN per la finanza locale o in WAN per sistemi di prenotazione proprietari (es. una singola compagnia aerea che gestisce i propri voli globalmente). 1.4 DDBMS ETEROGENEI (MULTIDATABASE) I nodi usano software diversi (es. alcuni MySQL, altri SQL Server, altri MongoDB). ● Sfida: È molto difficile da gestire perché bisogna usare dei "traduttori" (chiamati Gateway o Middleware) per far capire ai diversi sistemi cosa stanno facendo gli altri. ● Tabella: Sono tipici dei sistemi Inter-Banking o sistemi di prenotazione Integrati. Ad esempio, quando prenoti un viaggio che include volo (compagnia A), hotel (catena B) e auto (noleggio C), il sistema deve far dialogare database completamente diversi tra loro.

1.4.1 LOCAL INDEPENDENCY AND COOPERATION

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.

1.4.2 DATA FRAGMENTATION

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

  • each Ri has a subset of the tuples in R
  • each Ri can be interpreted as the result of a selection over R Vertical fragmentation
  • each Ri has, in its schema, a subset of the attributes in R
  • each Ri can be interpreted as the result of a projection over R

Allocation can be:

  • non-redundant: each fragment or relation is allocated to one server only.
  • redundant: at least one fragment or relation is allocated to multiple servers. Distinguishing between fragmentation and allocation permits to write applications operating at different levels: from the most abstract and independent from data fragmentation, to the most concrete and dependent on their physical allocation.

1.4.4 TRANSPARENCY LEVEL

There are 4 different levels of transparency that describe how much the programmer needs to know

about the physical structure of the distributed DB for writing queries:

  1. Fragmentation is the highest level of transparency. The programmer: does not need to know the fragmentation does not need to know the allocation
  2. Allocation is the intermedial level of transparency. The programmer: needs to know the structure of fragments does not need to know the allocation
  3. Language is the lowest level of transparency. The programmer: needs to know the structure of fragments needs to know the allocation
  4. No transparency is the worst case. The programmer must handle fragmentation, allocation, and adapt queries to each server's specific SQL dialect, as no common interoperability standard is supported. La trasparenza in un database distribuito (DDB) è quella "illusione" fornita dal sistema che permette all'utente di interagire con il database come se fosse un unico sistema centralizzato, nascondendo la complessità della distribuzione dei dati. Trasparenza alla Frammentazione (Massima): Vedi il database come un'unica tabella unita. Non sai né come è divisa, né dove si trova. Trasparenza all'Allocazione (Media): Sai che la tabella è divisa in pezzi (frammenti), ma non sai su quali server fisici siano salvati. Trasparenza del Linguaggio (Bassa): Devi conoscere sia i frammenti sia l'indirizzo del server specifico (es. Tabella@Server_Roma) per fare una query. Nessuna Trasparenza (Minima): Devi gestire tutto a mano: frammenti, posizioni dei server e persino le differenze di linguaggio tra SQL diversi. Query optimization

The application can be optimized through two dimensions:

  • Parallelism → Instead of sending requests to the various servers sequentially (one at a time), they

are sent all at once in parallel. This significantly reduces the overall response time — it is like

asking multiple people to search for something at the same time instead of having them search one at a time.

  • knowledge of the logical properties of fragments → The programmer knows exactly which

fragment contains the data they need, and therefore queries only that fragment directly

instead of searching across all of them.

Esempi

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.

1. Fragmentation: the programmer

does not need to know the fragmentation

does not need to know the allocation

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;

2. Allocation: the programmer

needs to know the structure of fragments

does not need to know the allocation

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;

3. Language: the programmer

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

4. No transparency

each DBMS accepts its own SQL dialect: the system is heterogeneous and the DBMSs do not support a common interoperability standard

Esempi 2

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:

Le transizioni sono composte da più azioni, che fanno però 1 lavoro specifico. Progressively increasing

complexity levels

1.5.1 REMOTE REQUESTS

1. Remote requests: la transizione più semplice di questo scenario, è read only, e contiene un

numero arbitrario di query SQL. Quindi viene fatta una sola domanda a un certo DBMS (es. SELECT certe informazioni di un certo DB)

1.5.2 REMOTE TRANSACTIONS

2. Remote transactions: sempre composto da un numero arbitrario di commandi SQL, SELECT,

INSERT, DELETE, UPDATE.

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, …)

1.5.3 DISTRIBUTED TRANSACTIONS

3. Distributed transactions: Composed of an arbitrary number of SQL commands (select, 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.

1.5.4 DISTRIBUTED REQUESTS

4. Distributed requests: Arbitrary transactions composed of an arbitrary number of SQL

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

Il livello massimo di complessità. Un singolo comando SQL può coinvolgere dati sparsi su più server diversi

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

CC1 → to CC2 per questo è una transazione distribuita

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

succede un FAIL → UNDO e sono neccesari delle REDO after commit

Le transazioni possiibli sono:

  • commit
  • rollback requested by the application: suicide
  • rollback requested by the system: homicide 1.6. 2 CONSISTENCY Consistency: quando si esegue non deve contrastare l’integrità dei vincoli, The execution of a transaction should not violate integrity constraints defined for the database Integrity checks can be:
  • immediate: during the transaction (the operation causing the violation is refused)
  • deferred: at the end of the transaction (if constraints are violated, the whole transaction is refused) 1.6. 3 ISOLATION Isolation: ogni transazione è indipendente dalle esecuzioni di altre; The execution of a transaction should be independent from the execution of any other concurrent transaction Concurrent execution of a set of transactions should lead to the same result as an arbitrary sequential execution of the same transactions 1.6. 4 DURABILITY

Durability: gli effetti delle transazioni sono duraturi

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

Mentre la Consistenza e la Persistenza possono essere gestite localmente dai singoli nodi, l'Atomicità

e l'Isolamento diventano problemi " globali".

Data distribution affects

  • isolation: L'isolamento serve a far sì che transazioni parallele non interferiscano tra loro. In un database distribuito, mantenere l'isolamento è estremamente complesso a causa della mancanza di una memoria condivisa e dei ritardi di rete
  • atomicity: In un sistema locale, l'atomicità è semplice: se il disco non fallisce, la transazione scrive tutto; se c'è un errore, si fa il rollback. In un sistema distribuito, una transazione è composta da diverse sotto-transazioni su nodi diversi.

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

The projection of S on node i must be equal to S

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).

VSR: View → Uno schedule è VSR se è "View-Equivalent" a uno schedule seriale. Ovvero, le transazioni "vedono"

le stesse cose e lasciano il database nello stesso stato finale.

CSR: Conflit → no schedule è CSR se può essere trasformato in uno seriale (uno dopo l'altro) scambiando tra loro solo

operazioni adiacenti che non confliggono.

*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

If two processes do not interact it is not necessary that they are synchronized

No matter that all processes agree on what time it is, but on the order in which events occur Lamport

clocks and Vector clocks are based on these observations

Quindi è necessario identificare qual’è la prima, la seconda, … se i processi interagiscono tra di loro,

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

a is the event of sending a message and b is the event of receiving the message The relationship is

transitive (a → b, b → c, a→c)

Events in different transactions that do not exchange messages are concurrent: it is a partial order

relationship

1.8.1 LAMPORT CLOCK:

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.:

  • If a and b are two events in the same transaction, and a→b, then C(a) Gli orologi di Lamport servono a dare un ordine totale (mettere in fila i numeri), ma sono "ciechi" rispetto alla causalità reale. Non sanno distinguere tra:
  1. Due eventi legati (uno ha causato l'altro).
  2. Due eventi totalmente indipendenti che per puro caso hanno ricevuto timestamp diversi. Per risolvere questo specifico problema e "catturare la causalità", gli ingegneri usano i Vector Clocks (Orologi Vettoriali), dove ogni nodo tiene traccia degli orologi di tutti gli altri.

1.8.2 VECTOR CLOCK

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:

1. Come funziona l'algoritmo

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).

2. Perché "catturano la causalità"?

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.

3. Esempio Pratico

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)

  1. Before executing an event VCi [i]= VCi [i] + 1
  2. When b, the timestamp ts(m)[1...n] of m is set to VCi [1…n] after the above operation
  3. When receiving a message m from Pj , VCi [k] is adjusted to max{VCi [k], ts(m)[k]}; then executes step 1 before passing m to the application
  4. VCi [i] = VCi [i] + 1 (L'Evento Locale)

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].

  1. Impostazione del Timestamp del Messaggio (ts(m)) Quando Pi vuole inviare un messaggio m:
    1. Prima incrementa il proprio contatore (passo 1).
    2. Poi "fotocopia" il suo intero vettore e lo attacca al messaggio. ● Significato: "Ti mando questo dato e ti dico anche tutto quello che so finora su quanto è successo su tutti i nodi del sistema".
  2. Ricezione e Aggiustamento (Il "Merge") Quando il processo Pi riceve un messaggio m dal processo Pj: ● Il confronto (max): Pi guarda il vettore ricevuto e lo confronta con il suo, elemento per elemento. Per ogni posizione k, prende il valore massimo. ○ Esempio: Se P1 ha [2, 0, 5] e riceve un messaggio con [1, 4, 3], il nuovo vettore sarà [\max(2,1), \max(0,4), \max(5,3)] = [2, 4, 5]. ● L'aggiornamento finale: Dopo aver sincronizzato le conoscenze, $P_i$ incrementa di nuovo la propria posizione (passo 1) per segnare l'evento della ricezione stessa. Il vettore finale sarà [3, 4, 5]. es [x,y,z,w] P1, P2, P3, P4: ognuno ha un suo vettore con 4 elementi [ ,,, ] Le transazioni sono su diversi nodi, e ci sono i problemi in merito ai Distributed deadlock, ovvero circular wait condition, che per iniziare un’operazione è necessario che una finisca.

Circular waiting between two or more nodes, solutions

per risolvere questo problema di deadlock, ci possono esere 2 modi:

  1. time-out → used by distributed DBMSs, kill the transaction
  2. deadlock detection and resolution → can be performed through an asynchronous and distributed protocol assume that sub-transactions can be activated using remote procedure call (RPC) per trovare questi problemi, è possibile vedere come comunicano i due DBMS, per trovare e controllare i deadlock waiting conditions: Ein → ti → tj → Eout DBMS1: E2 → t2→t1→ E DBMS2: E1 → t1→t2→ E

2.1 ONE PHASE COMMIT

Simple solution, based on role, a role of coordinator.

Starting with a transaction t that is divided in t1,t2,t3,t4,… running in different nodes 𝑡ଵ @𝑛ଵ 𝑡ଶ @𝑛ଶ

𝑡ଷ @𝑛ଷ → like this is elected like coordinators

𝑡ସ @𝑛ସ → 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 just decides directly what happens and tells everyone: Commit now, or, Abort now, so

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

cannot commit, so tell this to the coordinator and find that there is an error (ex the t4@n4)

So, the atomicity is broken, some nodes commit and other’s don’t.

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.

2.2.0 ACTORS IN TWO PHASE COMMITTEES

The commit/abort decision is taken by the parties and registered by a coordinator, distinguishing between:

  • servers that participate in the decision: resource managers (RM), they are the nodes that execute regularly the transaction, and do locally the operation and when they have to prepare the result, the send YES or NO to tells to the coordinator if they are ready or not.

o this can lock the resource if there are some problem

  • coordinator process: transaction manager (TM) that managing the nodes. SO ask to other nodes if they can do a COMMIT or ABORT, and tells to the other the final decision, so global one. Works through the rapid exchange of messages (broadcast or serial) between TM and RM, and writing record logs. TM and RM maintain logs to guarantee resistance to failures, logs are important to make sure what happened, and to recall the failure and fix them. So, the idea is ALL PARTICIPANTS MUST AGREE first, then a final decision is taken.

2 phases of the two-phase commit:

1. Voting phase: goes to the coordinator to the participant and collect the answer

  1. TM sends VOTE_REQUEST to RMs
  2. RMs replies with VOTE_COMMIT or VOTE_ABORT

2. Decision phase: broadcasting the answer

  1. If all RMs vote commit → TM sends GLOBAL_COMMIT if at least one RM votes abort → TM sends GLOBAL_ABORT
  2. RMs who voted commit wait for a message from the TM: GLOBAL_COMMIT → locally commits its operations GLOBAL_ABORT → locally aborts its operations

Utility of logs

È 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

wait the commit from that node, but if cannot, logs are necessary to find where the problem is, so in

which phase I’m.

Log: transaction manager - coordinator

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.

Log: resource manager - one participant

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

  • uncertainty windows (should be minimized)
  • the resources acquired by the transaction are blocked Il RM non può più decidere da solo di abortire ma si deve aspettare la decisione finale del TM (COMMIT or ABORT). Before declaring the decision or declaring non-ready, RM can abort autonomously undoing its effects, without participating in the two-phase commit protocol So the log are used to guarantee atomicity and in the case of crash, it know where the problem is.