DiskMgr Class Reference
#include <DiskMgr.h>
Public Member Functions |
| DiskMgr () |
| ~DiskMgr () |
int | Initialize (DiskMgrConfig *Config) |
int | BuildNode (char *hostname, bool Connect) |
int | Start () |
int | Stop () |
int | CleanUp () |
int | AllocMult (int numReplicas, RioDiskBlock *rep, unsigned long long int ExcludeStorages) |
int | Alloc (RioDiskBlock *rep, unsigned long long int ExcludeStorages) |
int | Free (RioDiskBlock *rep) |
int | Reset () |
int | Confirm () |
int | Format () |
void | SendStorageNode (EventStorageRequest *event, u16 DiskId) |
int | GetNumberOfStorageNodes (unsigned int *NumberOfStorageNodes) |
int | GetStorageNodeInfo (unsigned int StorageNodeIndex, RioStorageNodeInfo *StorageNodeInfo) |
int | GetDiskStorageNodeInfo (unsigned int DiskId, RioStorageNodeInfo *StorageNodeInfo) |
int | GetMaxNumberOfDisks () |
int | GetNumberOfActiveDisks (unsigned int *NumberOfDisks) |
int | GetDiskName (unsigned int DiskId, char *DiskName) |
int | GetDiskServiceTime (EventStorageRequest *event, u16 DiskId) |
unsigned int | GetDiskNumberOfFreeBlocks (unsigned int DiskId) |
int | GetStorageServersAddress (SOCKADDR_IN *ServerAddress) |
| Funcao para obter todos os enderecos (pares IP e porta) dos Storage Servers (que estao listados no arquivo RIOdisk.cfg).
|
int | SendStorageNodeByIP (EventStorageRequest *event, u32 StorageIP) |
| Nova funcao, usada pelo gerenciamento de logs, para colocar um evento na fila de eventos (com mensagens a serem enviadas) ao servidor de armazenamento identificado pelo IP dado com parametro.
|
int | GetNumberOfReplications (void) |
| Nova funcao para obter o numero de replicacoes de cada bloco.
|
int | GetNumberOfNeededDisks (unsigned int *NumberOfDisks) |
| Nova funcao para retornar o numero minimo de discos necessarios para inicializar as estruturas do servidor.
|
Private Member Functions |
int | ReadConfiguration () |
void | BuildAlloc () |
bool | CheckDiskAlloc (int num, RioDiskBlock *rep, int choice) |
int | LoadDisksBitMaps (unsigned int StorageId) |
| Nova funcao para carregar os BitMaps dos discos associados a um servidor de armazenamento.
|
int | FreeSalvedBlocks (const char *StorageName) |
| Nova funcao para liberar os blocos salvos no arquivo de um servidor de armazenamento.
|
Private Attributes |
int | m_BlockSize |
int | m_MaxDisks |
int | m_MaxReps |
char * | m_MetaRoot |
CRouter * | m_Router |
CSystemManager * | m_SystemManager |
int | m_cntAllocMult |
int | m_cntAllocRetry |
int | m_cntAllocFail |
pthread_mutex_t | m_mutex |
int | m_numDisks |
Disk ** | m_disks |
int | m_NumberOfActiveDisks |
int | m_NumberOfStorageNodes |
ofstream | m_log |
int | m_diskanum |
Disk ** | m_diska |
Disk * | m_disklist |
SNode * | m_nodelist |
pthread_t | m_thread |
int | m_termflag |
char * | m_ConfigsDirectory |
unsigned int | m_MaxAttempts |
unsigned int | m_TimeBetweenAttempts |
unsigned long long int | m_storagesnotfull |
bool | m_IsFormatting |
Friends |
class | Disk |
class | SNode |
Detailed Description
Definition at line 37 of file DiskMgr.h.
Constructor & Destructor Documentation
Member Function Documentation
int DiskMgr::Alloc |
( |
RioDiskBlock * |
rep, |
|
|
unsigned long long int |
ExcludeStorages | |
|
) |
| | |
int DiskMgr::AllocMult |
( |
int |
numReplicas, |
|
|
RioDiskBlock * |
rep, |
|
|
unsigned long long int |
ExcludeStorages | |
|
) |
| | |
Definition at line 841 of file DiskMgr.cpp.
00843 {
00844 int i, x, rc;
00845 Disk *dp;
00846 int cntretry = 0;
00847 int maxretry = ( SNode::sn_maxdisks + 1 ) * numReplicas;
00848 unsigned long long int storages_disp;
00849
00850
00851 int numStorages = ( m_numDisks - 1 ) / SNode::sn_maxdisks;
00852
00853
00854 if( numReplicas > numStorages ) numReplicas = numStorages;
00855
00856
00857 for( i = 0; i < numReplicas; i++ )
00858 {
00859 memset(&rep[i], 0, sizeof(RioDiskBlock));
00860 }
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883 storages_disp = ~ ( ExcludeStorages | ( ~m_storagesnotfull ) );
00884
00885 for( i = 0; i < numReplicas; i++ )
00886 {
00887 m_cntAllocMult++;
00888 retry:
00889
00890
00891 #ifdef __GENERATE_DISKLOG
00892 if( m_log.is_open() )
00893 {
00894 m_log << "Tentando obter um disco de um storage " << endl;
00895 }
00896 #endif
00897
00898 #ifdef RIO_DEBUG2
00899 RioErr << "DiskMgr::AllocMult storages que nao podem ser usados "
00900 << "(ExcludeStorages = ";
00901 for( int p = MAXNUMSTORAGES - 1; p >= 0 ; p--)
00902 {
00903 unsigned int q = ( ExcludeStorages >> p ) & 1ull;
00904 RioErr << q;
00905 }
00906 RioErr << ")" << endl;
00907 RioErr << "DiskMgr::AllocMult storages cujos discos nao estao cheios "
00908 << "(m_storagesnotfull = ";
00909 for( int p = MAXNUMSTORAGES - 1; p >= 0 ; p--)
00910 {
00911 unsigned int q = ( m_storagesnotfull >> p ) & 1ull;
00912 RioErr << q;
00913 }
00914 RioErr << ")" << endl;
00915 RioErr << "DiskMgr::AllocMult storages que pode ser usados "
00916 << "(storages_disp = ";
00917 for( int p = MAXNUMSTORAGES - 1; p >= 0 ; p--)
00918 {
00919 unsigned int q = ( storages_disp >> p ) & 1ull;
00920 RioErr << q;
00921 }
00922 RioErr << ")" << endl;
00923 #endif
00924
00925
00926
00927
00928
00929
00930
00931 if( storages_disp == 0 )
00932 return ERROR_DISKMGR + ERROR_DISKFULL;
00933
00934 do
00935 {
00936
00937 x = RandomNumber( m_diskanum );
00938 dp = m_diska[x];
00939
00940 #ifdef __GENERATE_DISKLOG
00941 if( m_log.is_open() )
00942 {
00943 m_log << "DiskMgr::AllocMult replicacao " << i+1 << ", x = "
00944 << x << ", dp->d_diskid = " << dp->d_diskid
00945 << ", numero de blocos (do disco) = "
00946 << dp->d_BitMap.nFree() << ", storages_disp = ";
00947
00948 for(int p = MAXNUMSTORAGES - 1; p >= 0 ; p--)
00949 {
00950 unsigned int q = ( storages_disp >> p ) & 1ull;
00951 m_log << q;
00952 }
00953
00954 m_log << endl;
00955 }
00956 #endif
00957
00958 }
00959
00960 while( !( storages_disp &
00961 (1ull << ( ( dp->d_diskid - 1 ) / SNode::sn_maxdisks ) ) ) );
00962 if( CheckDiskAlloc( i, rep, dp->d_diskid ) )
00963 {
00964
00965 rc = dp->d_BitMap.AllocSeq(RandomNumber(dp->d_ntot), &rep[i].block);
00966 if( rc != 0 )
00967 return rc;
00968 rep[ i ].disk = dp->d_diskid;
00969
00970 #ifdef __GENERATE_DISKLOG
00971 if( m_log.is_open() )
00972 m_log << " AllocMult:: Chose Disk " << rep[ i ].disk
00973 << " block " << rep[ i ].block << endl;
00974 #endif
00975
00976 storages_disp -= ( 1ull << ( ( dp->d_diskid - 1 ) /
00977 SNode::sn_maxdisks ) );
00978 continue;
00979 }
00980 else
00981 {
00982 m_cntAllocRetry++;
00983 cntretry++;
00984
00985 #ifdef __GENERATE_DISKLOG
00986 if( m_log.is_open() )
00987 {
00988 m_log << "DiskMgr::AllocMult disco " << dp->d_diskid
00989 << " incorreto. Possivel erro de implementacao."
00990 << endl;
00991 m_log << "DiskMgr::AllocMult Failed for disk " << dp->d_diskid
00992 << " try " << cntretry << " from " << maxretry << endl;
00993 }
00994 #endif
00995
00996 if( cntretry < maxretry )
00997 {
00998
00999 BuildAlloc();
01000
01001
01002
01003
01004 storages_disp = storages_disp & m_storagesnotfull;
01005 goto retry;
01006 }
01007 m_cntAllocFail++;
01008
01009 return ERROR_DISKMGR + ERROR_UNEXPECTED;
01010 }
01011 }
01012 return 0;
01013 }
void DiskMgr::BuildAlloc |
( |
|
) |
[private] |
int DiskMgr::BuildNode |
( |
char * |
hostname, |
|
|
bool |
Connect | |
|
) |
| | |
Definition at line 421 of file DiskMgr.cpp.
00422 {
00423 SNode *np;
00424 int rc;
00425 EventStorageRequest *event;
00426 pthread_attr_t attribtx;
00427 pthread_attr_t attribrx;
00428
00429 #ifdef RIO_DEBUG1
00430 RioErr << "### [DiskMgr - BuildNode] Start" << endl;
00431 #endif
00432
00433
00434
00435 for( np = m_nodelist; np != 0; np = np->sn_link )
00436 {
00437 if( strcmp( np->sn_hostname, hostname ) == 0 )
00438 {
00439 if( m_log.is_open() )
00440 m_log <<"DiskMgr.BuildNode duplicate node for "
00441 << hostname << endl;
00442
00443
00444 m_log << "### [DiskMgr - BuildNode] Finish1" << endl;
00445
00446
00447 return -1;
00448 }
00449 }
00450
00451 np = new SNode( this, hostname );
00452
00453 if( ( np == 0 ) || ( np->sn_hostname == 0 ) )
00454 {
00455 RioErr << " error memory (could not create object)." << endl;
00456 delete np;
00457
00458 #ifdef RIO_DEBUG1
00459 RioErr << "### [DiskMgr - BuildNode] Finish2" << endl;
00460 #endif
00461
00462 return ERROR_MEMORY;
00463 }
00464
00465 np->sn_IPaddress.Host = vsiGetIPaddress( hostname );
00466 np->sn_IPaddress.Port = htons( 5101 );
00467
00468
00469
00470 if( Connect )
00471 {
00472
00473 rc = np->sn_socket.Connect( &np->sn_IPaddress );
00474
00475 if( rc )
00476 {
00477 RioErr << " connect failed for " << np->sn_hostname << ": "
00478 << GetErrorDescription(rc) << endl;
00479
00480 delete np;
00481
00482 RioErr << "### [DiskMgr - BuildNode] Depois do delete" << endl;
00483
00484 #ifdef RIO_DEBUG1
00485 RioErr << "### [DiskMgr - BuildNode] Finish3" << endl;
00486 #endif
00487
00488 return -1;
00489 }
00490
00491
00492 np->sn_isenabled = true;
00493
00494 np->sn_sendevent = false;
00495
00496 }
00497 else
00498 {
00499
00500 np->sn_isenabled = false;
00501
00502 np->sn_sendevent = true;
00503
00504
00505
00506
00507 EventStorageDown* event;
00508 event = ( EventStorageDown * ) EventManager.New( EventTypeStorageDown );
00509
00510 event->StorageId = ( m_numDisks - 1 ) / SNode::sn_maxdisks;
00511
00512
00513 event->EmptyStorageQueue = false;
00514
00515 RioErr << "Failed to connect to the storage " << np->sn_hostname
00516 << endl;
00517
00518 #ifdef RIO_DEBUG2
00519 RioErr << "DiskMgr::BuildNode enviando a mensagem "
00520 << "EventStorageDown ao Router do servidor de "
00521 << "armazenamento com a ID " << event->StorageId << endl;
00522 #endif
00523
00524 m_Router->Put( ( Event * ) event );
00525 }
00526
00527
00528
00529
00530 np->sn_diskidorg = m_numDisks;
00531 m_numDisks += SNode::sn_maxdisks;
00532
00533 m_NumberOfStorageNodes++;
00534
00535 pthread_attr_init( &attribtx );
00536 pthread_attr_init( &attribrx );
00537 pthread_attr_setstacksize( &attribtx, 2*PTHREAD_STACK_MIN );
00538 pthread_attr_setstacksize( &attribrx, 2*PTHREAD_STACK_MIN );
00539
00540 if( pthread_create( &np->sn_txthread, &attribtx,
00541 &SNode::txthreadep, (void *)np)
00542 )
00543 {
00544 if( m_log.is_open() )
00545 m_log << "tx pthread_create failed for " << hostname
00546 << " error: " << strerror(errno) << endl;
00547
00548 RioErr << " tx pthread_create failed for " << hostname << endl;
00549
00550 #ifdef RIO_DEBUG1
00551 RioErr << "### [DiskMgr - BuildNode] Finish4" << endl;
00552 #endif
00553
00554 return -1;
00555 }
00556
00557 if( pthread_create( &np->sn_rxthread, &attribrx,
00558 &SNode::rxthreadep, (void *)np)
00559 )
00560 {
00561 if( m_log.is_open() )
00562 m_log << "rx pthread_create failed for " << hostname
00563 << " error: " << strerror(errno) << endl;
00564
00565 RioErr << "rx pthread_create failed for " << hostname << endl;
00566
00567 #ifdef RIO_DEBUG1
00568 RioErr << "### [DiskMgr - BuildNode] Finish5" << endl;
00569 #endif
00570
00571 return -1;
00572 }
00573
00574 if( Connect )
00575 {
00576
00577
00578
00579
00580 event = (EventStorageRequest*) EventManager.New(
00581 EventTypeStorageRequest );
00582 event->StorageRequest.Header.Type = MSG_RSS_INITIALIZATION_REQ;
00583 event->StorageRequest.Header.Size = SizeMsgRSSInitializationReq;
00584 event->StorageRequest.Header.Token = RSS_TOKEN_ROUTER;
00585 MsgRSSInitializationReq* msg = & ( event->StorageRequest.
00586 Initialization );
00587 msg->BlockSize = m_BlockSize;
00588 np->sn_sendqueue.Put( ( Event* ) event );
00589
00590 }
00591
00592 struct in_addr address;
00593 address.s_addr = np->sn_IPaddress.Host;
00594
00595 AddNodeEvent *it_event = new AddNodeEvent( np->sn_hostname, inet_ntoa( address ) );
00596 m_SystemManager->PostITEvent( (MonitorEvent *)it_event );
00597
00598 #ifdef RIO_DEBUG1
00599 RioErr << "### [DiskMgr - BuildNode] Finish6" << endl;
00600 #endif
00601
00602 return 0;
00603 }
bool DiskMgr::CheckDiskAlloc |
( |
int |
num, |
|
|
RioDiskBlock * |
rep, |
|
|
int |
choice | |
|
) |
| | [private] |
Definition at line 742 of file DiskMgr.cpp.
00743 {
00744 Disk *dp, *rd;
00745 int j;
00746 bool isEnabled;
00747
00748 if( ( choice > m_MaxDisks ) || ( num > m_MaxReps ) )
00749 {
00750 #ifdef __GENERATE_DISKLOG
00751 if( m_log.is_open() )
00752 m_log << "DiskMgr::CheckDiskAlloc invalid input, choice "
00753 << choice << " num " << num << endl;
00754 #endif
00755 return false;
00756 }
00757
00758 dp = m_disks[choice];
00759
00760 if( dp == 0 )
00761 {
00762 #ifdef __GENERATE_DISKLOG
00763 if( m_log.is_open() )
00764 m_log << "DiskMgr::CheckDiskAlloc dp = 0" << endl;
00765 #endif
00766 return false;
00767 }
00768 if( ( dp->d_status & Disk::STAT_ALLOC ) == 0 )
00769 {
00770 #ifdef __GENERATE_DISKLOG
00771 if( m_log.is_open() )
00772 m_log << "DiskMgr.CheckDiskAlloc ( dp->d_status & "
00773 << "Disk::STAT_ALLOC ) == 0 (" << dp->d_status << ")" << endl;
00774 #endif
00775 return false;
00776 }
00777 if( dp->d_BitMap.nFree() <= 0 )
00778 {
00779 #ifdef __GENERATE_DISKLOG
00780 if( m_log.is_open() )
00781 m_log << "DiskMgr.CheckDiskAlloc dp->d_Bitmap.nFree() <= 0"
00782 << "(" << dp->d_BitMap.nFree() << ")" << endl;
00783 #endif
00784 return false;
00785 }
00786
00787
00788
00789
00790 pthread_mutex_lock( &dp->d_node->sn_mutex );
00791
00792 isEnabled = dp->d_node->sn_isenabled;
00793
00794 pthread_mutex_unlock( &dp->d_node->sn_mutex );
00795 if( !isEnabled )
00796 {
00797 #ifdef __GENERATE_DISKLOG
00798 if( m_log.is_open() )
00799 m_log << "DiskMgr.CheckDiskAlloc dp->d_node->sn_isenabled = false"
00800 << endl;
00801 #endif
00802 RioErr << "DiskMgr.CheckDiskAlloc dp->d_node->sn_isenabled = false"
00803 << endl;
00804 return false;
00805 }
00806
00807
00808
00809
00810
00811 for( j = 0; j < num; j++ )
00812 {
00813 rd = m_disks[rep[j].disk];
00814 if( rd == 0 )
00815 continue;
00816 if( rd->d_node == dp->d_node )
00817 {
00818 #ifdef __GENERATE_DISKLOG
00819 if( m_log.is_open() )
00820 m_log << "DiskMgr.CheckDiskAlloc rd->d_node == dp->d_node"
00821 << "(0x" << hex << ( unsigned int ) rd->d_node << ", 0x"
00822 << ( unsigned int ) dp->d_node << dec << ")" << endl;
00823 #endif
00824 return false;
00825 }
00826 }
00827 return true;
00828 }
Definition at line 143 of file DiskMgr.cpp.
00144 {
00145 return 0;
00146 }
Definition at line 685 of file DiskMgr.cpp.
00686 {
00687 Disk *dp;
00688 int rc = 0;
00689 int rc2;
00690
00691 for( dp = m_disklist; dp != 0; dp = dp->d_link )
00692 {
00693 rc2 = dp->d_BitMap.Confirm();
00694 if( rc2 && !rc )
00695 rc = rc2;
00696 }
00697 return rc;
00698 }
Definition at line 606 of file DiskMgr.cpp.
00607 {
00608 Disk *dp;
00609 int rc = 0;
00610 int rc2;
00611 unsigned int junk;
00612
00613 for( dp = m_disklist; dp != 0; dp = dp->d_link )
00614 {
00615 rc2 = dp->d_BitMap.Format();
00616
00617 if( !rc2 )
00618 {
00619 rc2 = dp->d_BitMap.AllocSeq( 0, &junk );
00620 }
00621 if( !rc2 )
00622 {
00623 rc2 = dp->d_BitMap.AllocSeq( 1, &junk );
00624 }
00625 if( rc2 && !rc )
00626 rc = rc2;
00627 }
00628
00629 if( !rc )
00630 {
00631 Confirm();
00632 BuildAlloc();
00633 }
00634 else
00635 {
00636 RioErr << "\n\n\n***************ERRO NO FORMAT!!!!*********" << endl;
00637 }
00638
00639 return rc;
00640 }
Definition at line 1022 of file DiskMgr.cpp.
01023 {
01024 Disk *dp;
01025
01026
01027 if( ( rep->disk == 0 ) && ( rep->block == 0 ) )
01028 {
01029 return 0;
01030 }
01031 if( ( rep->disk < 0 ) || ( rep->disk > m_MaxDisks ) )
01032 {
01033
01034 if( m_log.is_open() ) m_log << "DiskMgr.Free - invalid disk number "
01035 << rep->disk << endl;
01036 return ERROR_DISKMGR + ERROR_INVALID_DISK;
01037 }
01038 dp = m_disks[rep->disk];
01039 if( dp == 0 )
01040 {
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055 SNode *sp, *spsb;
01056 bool SaveBlock;
01057 SaveBlock = false;
01058 spsb = NULL;
01059 for( sp = m_nodelist; sp != 0; sp = sp->sn_link )
01060 {
01061
01062
01063
01064 if( ( rep->disk >= sp->sn_diskidorg ) &&
01065 ( rep->disk < ( sp->sn_diskidorg + SNode::sn_maxdisks ) ) )
01066 {
01067 if( ( !sp->sn_restart ) && ( !sp->sn_isenabled ) )
01068 {
01069 SaveBlock = true;
01070 spsb = sp;
01071 }
01072 break;
01073 }
01074
01075 }
01076
01077
01078
01079 if( SaveBlock )
01080 {
01081 char FreeBlocksFileName[ 2 * MaxPathSize + 1 ];
01082 int FreeBlocksFile;
01083 int BytesWroten;
01084 int error;
01085
01086
01087 spsb->sn_readfreeblocksfile = true;
01088
01089
01090
01091
01092 strcpy( FreeBlocksFileName, m_MetaRoot );
01093
01094 if( m_MetaRoot[ strlen( m_MetaRoot ) - 1 ] != '/' )
01095 strcat( FreeBlocksFileName, "/" );
01096
01097 strcat( FreeBlocksFileName, "FreeBlocks-" );
01098
01099 strcat( FreeBlocksFileName, spsb->sn_hostname );
01100 #ifdef RIO_DEBUG2
01101 RioErr << "DiskMgr::Free detectado que o servidor "
01102 << spsb->sn_hostname << " nao foi ainda inicializado. "
01103 << "Salvando o bloco " << rep->block << " associado ao "
01104 << "disco " << rep->disk << " no arquivo "
01105 << FreeBlocksFileName << " com os blocos a serem liberados "
01106 << " deste servidor" << endl;
01107 #endif
01108
01109 FreeBlocksFile = open( FreeBlocksFileName, O_WRONLY | O_APPEND |
01110 O_CREAT, 0700 );
01111 if( FreeBlocksFile < 0 )
01112 {
01113 #ifdef RIO_DEBUG2
01114 RioErr << "DiskMgr::Free erro " << errno << " ("
01115 << strerror( errno ) << ") ao abrir o arquivo "
01116 << FreeBlocksFileName << " com os blocos a serem salvos "
01117 << "do servidor de armazenamento " << spsb->sn_hostname
01118 << endl;
01119 #endif
01120 return ERROR_DISKMGR + ERROR_OPEN_FREEBLOCKS_FILE;
01121 }
01122
01123 BytesWroten = write( FreeBlocksFile, rep, sizeof( RioDiskBlock ) );
01124 error = errno;
01125 close( FreeBlocksFile );
01126 if( BytesWroten < 0 )
01127 {
01128 #ifdef RIO_DEBUG2
01129 RioErr << "DiskMgr::Free erro " << error << " ("
01130 << strerror( error ) << " ao gravar no arquivo "
01131 << FreeBlocksFileName << " com os blocos a serem salvos "
01132 << "do servidor de armazenamento " << spsb->sn_hostname
01133 << endl;
01134 #endif
01135 return ERROR_DISKMGR + ERROR_OPEN_FREEBLOCKS_FILE;
01136 }
01137 else if( BytesWroten != sizeof( RioDiskBlock ) )
01138
01139
01140 {
01141 #ifdef RIO_DEBUG2
01142 RioErr << "DiskMgr::Free foram gravados " << BytesWroten
01143 << " bytes ao inves de " << sizeof( RioDiskBlock )
01144 << " bytes no arquivo " << FreeBlocksFileName
01145 << " com os blocos a serem salvos do servidor de "
01146 << "armazenamento " << spsb->sn_hostname << endl;
01147 #endif
01148 return ERROR_DISKMGR + ERROR_OPEN_FREEBLOCKS_FILE;
01149 }
01150 else
01151
01152 return S_OK;
01153
01154 }
01155 else
01156 {
01157 #ifdef RIO_DEBUG2
01158 RioErr << "DiskMgr::Free Foi detectado que o bloco " << rep->block
01159 << " associado ao disco " << rep->disk << " e invalido"
01160 << endl;
01161 #endif
01162 return ERROR_DISKMGR + ERROR_INVALID_DISK;
01163 }
01164 }
01165
01166 dp->d_BitMap.Free( rep->block );
01167
01168
01169
01170 if( dp->d_BitMap.nFree() == 1 )
01171 {
01172 BuildAlloc();
01173 }
01174 memset(rep, 0, sizeof(RioDiskBlock));
01175 return 0;
01176 }
int DiskMgr::FreeSalvedBlocks |
( |
const char * |
StorageName |
) |
[private] |
Nova funcao para liberar os blocos salvos no arquivo de um servidor de armazenamento.
Estes blocos foram salvos porque, ao libera-los, o servidor de armazenamento ainda nao tinha inicializado e, em consequencia disso, os BitMaps dos seus discos ainda nao tinham sido carregados.
- Parameters:
-
| StorageName | nome da maquina com o servidor de armazenamento. |
- Returns:
- S_OK se nenhum erro ocorreu ao liberar os blocos do arquivo, ou diferente de S_OK caso algum erro ocorra ao liberar os blocos do arquivo.
Definition at line 1492 of file DiskMgr.cpp.
01493 {
01494 char FreeBlocksFileName[ 2 * MaxPathSize + 1 ];
01495 int FreeBlocksFile;
01496 int BytesRead;
01497 int error;
01498 RioDiskBlock Block;
01499
01500
01501
01502
01503 strcpy( FreeBlocksFileName, m_MetaRoot );
01504
01505 if( m_MetaRoot[ strlen( m_MetaRoot ) - 1 ] != '/' )
01506 strcat( FreeBlocksFileName, "/" );
01507
01508 strcat( FreeBlocksFileName, "FreeBlocks-" );
01509
01510 strcat( FreeBlocksFileName, StorageName );
01511 #ifdef RIO_DEBUG2
01512 RioErr << "DiskMgr::FreeSalvedBlocks liberando todos os blocos salvos no "
01513 << "arquivo " << FreeBlocksFileName << " associados aos discos do "
01514 << "servidor " << StorageName << endl;
01515 #endif
01516
01517 FreeBlocksFile = open( FreeBlocksFileName, O_RDONLY );
01518 if( FreeBlocksFile < 0 )
01519 {
01520 #ifdef RIO_DEBUG2
01521 RioErr << "DiskMgr::FreeSalvedBlocks erro " << errno << " ("
01522 << strerror( errno ) << " ao abrir o arquivo "
01523 << FreeBlocksFileName << " com os blocos a serem salvos do "
01524 << "do servidor de armazenamento " << StorageName << endl;
01525 #endif
01526 RioErr << "Reading blocks file " << FreeBlocksFileName << ": Failed"
01527 << endl;
01528 return ERROR_DISKMGR + ERROR_OPEN_FREEBLOCKS_FILE;
01529 }
01530
01531
01532 while( ( BytesRead = read( FreeBlocksFile, &Block,
01533 sizeof( RioDiskBlock ) ) ) == sizeof( RioDiskBlock ) )
01534 {
01535
01536 #ifdef RIO_DEBUG2
01537 RioErr << "DiskMgr::FreeSalvedBlocks removendo o bloco "
01538 << Block.block << " associado ao disco " << Block.disk
01539 << " lido do arquivo com os blocos " << FreeBlocksFileName
01540 << ": ";
01541 #endif
01542 if( m_disks[ Block.disk ] != NULL )
01543 {
01544 #ifdef RIO_DEBUG2
01545 RioErr << "OK" << endl;
01546 #endif
01547
01548 m_disks[ Block.disk ]->d_BitMap.Free( Block.block );
01549 }
01550 else
01551 {
01552
01553
01554 #ifdef RIO_DEBUG2
01555 RioErr << "Falhou. O disco " << Block.disk << " nao foi "
01556 << " inicializado." << endl;
01557 #endif
01558 RioErr << "Warning in read blocks file " << FreeBlocksFileName
01559 << ": disk " << Block.disk << " of fisical block "
01560 << Block.block << " is invalid" << endl;
01561 }
01562 }
01563 error = errno;
01564 close( FreeBlocksFile );
01565 if( BytesRead < 0 )
01566 {
01567 #ifdef RIO_DEBUG2
01568 RioErr << "DiskMgr::FreeSalvedBlocks erro " << error << " ("
01569 << strerror( error ) << " ao ler do arquivo "
01570 << FreeBlocksFileName << " com os blocos a serem salvos do "
01571 << "servidor de armazenamento " << StorageName << endl;
01572 #endif
01573 RioErr << "Reading blocks file " << FreeBlocksFileName << ": Failed"
01574 << endl;
01575 return ERROR_DISKMGR + ERROR_OPEN_FREEBLOCKS_FILE;
01576 }
01577 else if( BytesRead > 0 )
01578 {
01579 #ifdef RIO_DEBUG2
01580 RioErr << "DiskMgr::FreeSalvedBlocks foram lidos " << BytesRead
01581 << " bytes ao inves de " << sizeof( RioDiskBlock )
01582 << " bytes do arquivo " << FreeBlocksFileName
01583 << " com os blocos a serem salvos do servidor de "
01584 << "armazenamento " << StorageName << endl;
01585 #endif
01586 RioErr << "Reading blocks file " << FreeBlocksFileName << ": Failed"
01587 << endl;
01588 return ERROR_DISKMGR + ERROR_OPEN_FREEBLOCKS_FILE;
01589 }
01590 else
01591 {
01592 #ifdef RIO_DEBUG2
01593 RioErr << "DiskMgr::FreeSalvedBlocks removendo o arquivo "
01594 << FreeBlocksFileName << " com os blocos do disco " << endl;
01595 #endif
01596 RioErr << "Reading blocks file " << FreeBlocksFileName << ": Ok"
01597 << endl;
01598
01599 Confirm();
01600
01601 BuildAlloc();
01602
01603 remove( FreeBlocksFileName );
01604 return S_OK;
01605 }
01606 }
int DiskMgr::GetDiskName |
( |
unsigned int |
DiskId, |
|
|
char * |
DiskName | |
|
) |
| | |
Definition at line 1269 of file DiskMgr.cpp.
01270 {
01271 #ifdef RIO_DEBUG2
01272 if( m_log.is_open() ) m_log << "DiskMgr: GetDiskName " << DiskId <<endl;
01273 #endif
01274 if( m_disks[DiskId] != NULL )
01275 return m_disks[DiskId]->GetName( DiskName );
01276 else
01277 {
01278
01279
01280 DiskName[ 0 ] = 0;
01281 return 0;
01282 }
01283 }
unsigned int DiskMgr::GetDiskNumberOfFreeBlocks |
( |
unsigned int |
DiskId |
) |
|
Definition at line 1254 of file DiskMgr.cpp.
01255 {
01256 #ifdef RIO_DEBUG2
01257 if( m_log.is_open() )
01258 m_log << "DiskMgr: GetDiskNumberOfFreeBlocks disk " << DiskId <<endl;
01259 #endif
01260
01261 if( m_disks[DiskId] != NULL )
01262 return m_disks[DiskId]->GetNumberOfFreeBlocks();
01263 else
01264 return 0;
01265 }
Definition at line 1201 of file DiskMgr.cpp.
01202 {
01203 if( DiskId > m_MaxDisks )
01204 {
01205 #ifdef RIO_DEBUG2
01206 RioErr << "DiskMgr ERROR: GetDiskServiceTime request to invalid disk: "
01207 << DiskId << endl;
01208 #endif
01209 EventManager.Free((Event*) event);
01210 return -1;
01211 }
01212
01213 if( m_disks[DiskId] == 0 )
01214 {
01215 #ifdef RIO_DEBUG2
01216 RioErr << "DiskMgr ERROR: GetDiskServiceTime request to inactive disk: "
01217 << DiskId << endl;
01218 #endif
01219 EventManager.Free((Event*)event);
01220 return -1;
01221 }
01222 m_disks[DiskId]->GetServiceTime( event );
01223 return 0;
01224 }
int DiskMgr::GetDiskStorageNodeInfo |
( |
unsigned int |
DiskId, |
|
|
RioStorageNodeInfo * |
StorageNodeInfo | |
|
) |
| | |
Definition at line 1328 of file DiskMgr.cpp.
01330 {
01331 unsigned int SNId;
01332
01333 #ifdef RIO_DEBUG2
01334 if( m_log.is_open() ) m_log << "DiskMgr: GetDiskStorageNodeInfo DiskId "
01335 << DiskId << endl;
01336 #endif
01337
01338
01339
01340
01341
01342
01343 SNId = ( DiskId - 1 ) / SNode::sn_maxdisks;
01344
01345 GetStorageNodeInfo( SNId, StorageNodeInfo );
01346 return 0;
01347 }
int DiskMgr::GetMaxNumberOfDisks |
( |
|
) |
|
int DiskMgr::GetNumberOfActiveDisks |
( |
unsigned int * |
NumberOfDisks |
) |
|
int DiskMgr::GetNumberOfNeededDisks |
( |
unsigned int * |
NumberOfDisks |
) |
|
Nova funcao para retornar o numero minimo de discos necessarios para inicializar as estruturas do servidor.
O valor retornado sera a soma do numero descrito a seguir para cada um dos servidores de armazenamento. Para cada servidor de armazenamento, se ele tiver inicializado antes do servidor de gerenciamento o valor sera o numero de disco deste servidor e, em caso contrario, o numero maximo de discos, ou seja, SNode::sn_maxdisks = MAXSTORAGEDISKSARRAY
- Returns:
- Numero maximo de discos a serem usados.
Definition at line 1610 of file DiskMgr.cpp.
01611 {
01612 SNode *np;
01613 unsigned int NeededDisks;
01614 bool IsEnabled;
01615
01616 NeededDisks = 0;
01617
01618
01619
01620
01621
01622 for( np = m_nodelist; ( np != 0 ); np = np->sn_link )
01623 {
01624
01625 pthread_mutex_lock( &np->sn_mutex );
01626
01627 IsEnabled = np->sn_isenabled;
01628
01629 pthread_mutex_unlock( &np->sn_mutex );
01630 if( IsEnabled )
01631 NeededDisks = NeededDisks + np->sn_disks;
01632 else
01633 NeededDisks = NeededDisks + SNode::sn_maxdisks;
01634 }
01635
01636 *NumberOfDisks = NeededDisks;
01637
01638 return S_OK;
01639 }
int DiskMgr::GetNumberOfReplications |
( |
void |
|
) |
|
Nova funcao para obter o numero de replicacoes de cada bloco.
- Returns:
- numero de replicacoes para cada bloco.
Definition at line 1428 of file DiskMgr.cpp.
int DiskMgr::GetNumberOfStorageNodes |
( |
unsigned int * |
NumberOfStorageNodes |
) |
|
int DiskMgr::GetStorageNodeInfo |
( |
unsigned int |
StorageNodeIndex, |
|
|
RioStorageNodeInfo * |
StorageNodeInfo | |
|
) |
| | |
int DiskMgr::GetStorageServersAddress |
( |
SOCKADDR_IN * |
ServerAddress |
) |
|
Funcao para obter todos os enderecos (pares IP e porta) dos Storage Servers (que estao listados no arquivo RIOdisk.cfg).
- Parameters:
-
| ServerAddress | vetor de estruturas SOCKADDR_IN que armazenara, em cada uma de suas entradas, um par IP, porta de um Storage Server. |
- Returns:
- 0 (pois algumas funcoes da classe DiskMgr retornam um valor, mesmo que seja sempre igual a 0).
Definition at line 1358 of file DiskMgr.cpp.
01359 {
01360 SNode *np;
01361 unsigned int i = 0;
01362
01363
01364
01365 np = m_nodelist;
01366
01367
01368 while ( np != 0 ) {
01369
01370
01371
01372
01373 ServerAddress[ i ].sin_family = AF_INET;
01374 ServerAddress[ i ].sin_port = htons( STORAGESERVERUDPPORT );
01375 ServerAddress[ i ].sin_addr.s_addr = np->sn_IPaddress.Host;
01376 i++;
01377 np = np->sn_link;
01378 }
01379
01380 return 0;
01381 }
int DiskMgr::LoadDisksBitMaps |
( |
unsigned int |
StorageId |
) |
[private] |
Nova funcao para carregar os BitMaps dos discos associados a um servidor de armazenamento.
Esta funcao e usada para carragar os BitMaps do disco associados a um servidor de armazenamento que inicializou depois do servidor de gerenciamento, pois neste caso estes BitMaps nao vao ter sido carragados pela funcao Start da classe DiskMgr.
- Parameters:
-
| StorageId | identificador do servidor de armazenamento. servidor de armazenamento. |
- Returns:
- S_OK se nenhum erro ocorreu ao carragar os bitmaps ou o codigo de erro caso nao tenha sido possivel carragar um dos bitmaps.
Definition at line 1438 of file DiskMgr.cpp.
01439 {
01440 Disk *dp;
01441 int rc = 0;
01442 int rc2;
01443 unsigned int DiskStorageId;
01444
01445
01446 pthread_mutex_lock( &m_mutex );
01447
01448 for( dp = m_disklist; dp != 0; dp = dp->d_link )
01449 {
01450 DiskStorageId = ( dp->d_node->sn_diskidorg - 1 ) / SNode::sn_maxdisks;
01451 if( StorageId == DiskStorageId )
01452 {
01453
01454 #ifdef RIO_DEBUG2
01455 RioErr << "DiskMgr::LoadDisksBitMaps tentando carregar o BitMap "
01456 << " do disco com a ID " << dp->d_diskid << " associado ao "
01457 << "servidor de armazenamento com a ID " << DiskStorageId
01458 << endl;
01459 #endif
01460
01461 rc2 = dp->d_BitMap.Load();
01462 if( rc2 && !rc )
01463 rc = rc2;
01464
01465 #ifdef RIO_DEBUG2
01466 RioErr << "DiskMgr::LoadDisksBitMaps a carga do BitMap executou "
01467 << "com o erro rc2 = " << rc2 << endl;
01468 #endif
01469 }
01470 }
01471
01472 if( rc )
01473 {
01474
01475 pthread_mutex_unlock( &m_mutex );
01476
01477 return rc;
01478 }
01479
01480 BuildAlloc();
01481
01482
01483 pthread_mutex_unlock( &m_mutex );
01484
01485 return 0;
01486 }
int DiskMgr::ReadConfiguration |
( |
|
) |
[private] |
Definition at line 299 of file DiskMgr.cpp.
00300 {
00301 int rc = 0;
00302 char *nodename = 0;
00303
00304
00305 char ConfigFileName[ MaxPathSize ];
00306
00307
00308 int rc2;
00309 unsigned int Attempts;
00310
00311
00312
00313
00314
00315 unsigned int NumStorages;
00316
00317 cout << endl << " Reading DiskMgr configuration "
00318 << CONFIGNAME << " ... ";
00319
00320 token tok;
00321
00322
00323
00324
00325
00326 strcpy( ConfigFileName, m_ConfigsDirectory );
00327 strcat( ConfigFileName, CONFIGNAME );
00328
00329 if( tok.openfile( ConfigFileName ) )
00330 {
00331 m_log << "erro no tok.openfile " << CONFIGNAME << endl;
00332 return 1;
00333 }
00334
00335 NumStorages = 0;
00336
00337 int word;
00338 while( ( word = tok.parseline( mykeys ) ) >= 0 )
00339 {
00340 switch( word )
00341 {
00342 case k_disk:
00343 m_log << "erro k_disk." << endl;
00344 tok.emsg("not yet implemented");
00345 break;
00346
00347 case k_node:
00348 if( tok.getstrnew( &nodename ) )
00349 {
00350 tok.emsg("missing storage node hostname");
00351 break;
00352 }
00353
00354
00355 Attempts = 0;
00356 do
00357 {
00358 Attempts++;
00359 RioErr << "Trying to connect for " << Attempts + 1 << " time. Start" << endl;
00360 rc2 = BuildNode( nodename, true );
00361 RioErr << "Trying to connect for " << Attempts + 1 << " time. End" << endl;
00362 if( ( Attempts < m_MaxAttempts ) && ( rc2 ) )
00363 {
00364 RioErr << "Error connecting to storage server \""
00365 << nodename << "\" (attempt " << Attempts + 1
00366 << " of " << m_MaxAttempts << ")." << endl;
00367 RioErr << "Waiting for " << m_TimeBetweenAttempts << " seconds." << endl;
00368 sleep( m_TimeBetweenAttempts );
00369 }
00370 } while ( ( Attempts < m_MaxAttempts ) && ( rc2 ) );
00371
00372
00373 if( rc2 )
00374 {
00375 if( m_IsFormatting )
00376 RioErr << "Failed to connect to storage server \""
00377 << nodename << "\" when formatting file system. "
00378 << "Aborting. " << endl;
00379 else
00380 {
00381 RioErr << "Failed to connect to storage server \""
00382 << nodename << "\". Creating only the node for "
00383 << "this server" << endl;
00384 rc2 = BuildNode( nodename, false );
00385 }
00386 }
00387 rc |= rc2;
00388 m_log << "erro k_node. rc = " << rc << endl;
00389 NumStorages++;
00390 if( NumStorages > MAXNUMSTORAGES )
00391 {
00392 m_log << "Too many storage servers (max = "
00393 << MAXNUMSTORAGES << endl;
00394 return 1;
00395 }
00396
00397 delete[] nodename;
00398 break;
00399
00400 default:
00401 m_log << "erro invalid word." << endl;
00402 tok.emsg("{default} invalid word");
00403 continue;
00404 }
00405 tok.ckend();
00406 }
00407 tok.closefile();
00408
00409 if( rc == 0 )
00410 {
00411 cout << " OK. " << endl;
00412 }
00413 else
00414 cout << " Error! " << endl;
00415 return rc;
00416 }
int DiskMgr::Reset |
( |
void |
|
) |
|
Definition at line 668 of file DiskMgr.cpp.
00669 {
00670 Disk *dp;
00671 int rc = 0;
00672 int rc2;
00673
00674 for( dp = m_disklist; dp != 0; dp = dp->d_link )
00675 {
00676 rc2 = dp->d_BitMap.Reset();
00677 if( rc2 && !rc )
00678 rc = rc2;
00679 }
00680 return rc;
00681 }
Nova funcao, usada pelo gerenciamento de logs, para colocar um evento na fila de eventos (com mensagens a serem enviadas) ao servidor de armazenamento identificado pelo IP dado com parametro.
Obs: estamos supondo que o IP do servidor de armazenameno para a conexao TCP e o mesmo do que o da conexao UDP.
- Returns:
- S_OK se existe um servidor de armazenamento com este IP, ou o valor ERROR_UNEXPECTED se nao existir um servidor com o IP.
Definition at line 1391 of file DiskMgr.cpp.
int DiskMgr::Start |
( |
void |
|
) |
|
Definition at line 643 of file DiskMgr.cpp.
00644 {
00645 Disk *dp;
00646 int rc = 0;
00647 int rc2;
00648
00649 for( dp = m_disklist; dp != 0; dp = dp->d_link )
00650 {
00651 rc2 = dp->d_BitMap.Load();
00652 if( rc2 && !rc )
00653 rc = rc2;
00654 }
00655
00656 if( rc )
00657 {
00658 return rc;
00659 }
00660
00661 BuildAlloc();
00662 return 0;
00663 }
Friends And Related Function Documentation
friend class Disk [friend] |
friend class SNode [friend] |
Field Documentation
The documentation for this class was generated from the following files: