存档

‘科技’ 分类的存档

Review: C program

2007年8月20日 没有评论

The getc() function reads the next character from a file stream, and returns the character as an integer.

getchar == getc(stdin)
syntax: int getchar(void)

getchar() has its default file stream-stdin.
putc writes a character to the specified file stream.
syntax: int putc(int c, File * stream)
Here int c indicates that the output is a character saved in an integer variable C.
File stream specifies a file stream.

putchar syntax: int putchar(int c)

printf syntax:
int printf(const char* formating_string,…),it returns a negative value if an error occurs.
%d,%c are format specifiers.Please remember that you should use exactly the same number of expressions as the number of format specifies within the format string.

Hexadecimal, base 16 numbering system. A Hexadecimal number can be represented by four bits. The Hexadecimal number 0 through 9 map to decimal 0~9. upper case A~f means 10~15. Minimum Field Width, integer between the percent sign(%) and the letter in format specifies.

When the minimum field width is shorter than the width of the output, the latter is taken, and the output is still printed in full.

Align output: You can changed this and force outpyt to be left. To do so, you need to prefix the minimum field specifier with the minus sign(-).

Assignment Operator =
Relational Operator == (equal-to operator)
+=: do the addtion and the assignment later.
-: unary minus operator

++x: x = x + 1
pre-increment operator: the operator adds 1 to x first and then get the values of x.
–x: pre-decrement operator.

x++: x = x + 1
post-increment. For exampel, in the y = x++; statement, y is assigned the original value of x, not the one after x is increase by 1. In other words, the post-increment operator makes a copy of the original value of x and stores the copyu in a temporary location. Then x is increased by 1. However, instead of the modified value of x, the copy of the unmodified value of x is returned and assigned to y.

Relational Operations:
== Equal to
!= Not equal to
> Greater than
< Less than >= Greater than and Equal
<= Less than and Equal Important, all relational expression product a result of either 0 or 1. If a relation expression returns 1 if the specified relationship holds. Otherwise, 0 is returned. Be careful when you compare two values for equality. Because of the truncation, or rounding up, some relational expressions, which are algebraically true, may return 0 instead of 1. For example, 1/2 + 1/2 == 1 will return 0, which means that the equal-to relationship does not hold. This is because the truncation of the integer division--that is,1/2 produces 0, not 0.5. For the same reason, 1.0/3/0 + 1.0/3/0 + 1.0/3.0 == 1.0 will return 0. Cast operator: convert one data type to a different one by prefixing the case operator. Syntax or general form: (data-type)x. Here x is a variable(or, expression) that contains the value of the current data type. Looping, or iteration, is used in programing to perform the same set of statements over and over untill certain specified conditions are met. The for statement first evaluates expression 1, which usually initialized one or more variables. In other words, expression 1 is only evaluated once when then for statement is first encounted. The second expression, expression 2, is the conditional part that is evaluated right after the evaluation of expression 1 and then is evaluated after each successful looping by the for statement. If expression 2 returns a nonzero value, the statements within the braces are executed, Usually, the nonzero value is 1, If expression 2 returns 0, the looping is stopped and the execution of the for statement is finished. The third expression in the for statement, expression 3, is not evaluated when the for statement is first encounted. However, expression 3 is evaluated after each looping and before the statement goes back to test expression 2 again. The null statement: For example for(i=1;i<9;i++); means for(i=1;i<9;i++) ; Compare the following two: 1. for(i=1;i<9;i++); sum += i; 2. for(i=1;i<9;i++) sum += i; The result is not same. The null statement is perfectly legal in C. You should pay attention to placing semicolons in your for statement. Playing with an Infinite Loop: for(;;){ /* statement block*/ } There're no expressions in the three expression fields. The statements inside the statement block will be executed over and over without stopping. While (1){ /* statement block*/ } --> Note, there’s NOT semicolon here.

do{
/* statement block*/
} while(expression); –> Note, there’s semicolon here.
The do-while statement ends with a semicolon which is an important distinction form the if and while statement. The for statement does not end with semicolon.

How do you know the size of a data type on your machine? sizeof(expression)
Here expression is the data type or variable whose size is measured. The value of the size is returned ,in writes of bytes.
size = sizeof(int)
sizeof(char)
sizeof(float)
sizeof(double)

&& Logical AND
|| Logical OR
! Logical negation

In C, if an expression or operator returns a nonzero value, the expression return TRUE.If and expression or operator return 0, the expression return FALSE. In other words, TRUE can be used to represent any nonzero value returned by an expression or operator;FALSE is equivalent to 0.

分类: 科技 标签:

CTDB Introduction

2007年8月17日 没有评论

CTDB, Cluster Trival Database.
1. Consistent data and consistant locking
2. If one node failed, CTDB will automatically recovery and repair all CTDB database.
3. CTDB is PCIFS, parallel CIFS with samba 3/4
4. Support TCP and Infiniband

Requirement:
This filesystem must be mounted and available on all nodes in the CTDB cluster.

HA Features:
The CTDB nodes in a cluster designates one nodes as recovery master through an election process. If the recovery master node failes a new election is initiated so that the cluster will always guarantee there will be a recovery master. The recovery master will continously monitor the cluster to verify that all nodes contain a consistant configuration and view of the cluster and will initiate a recovery process when required.

During the recovery phase, the recovery master will automatically rebuild/recovery all clustered TDB database to ensure that the database are consistent. Recovery typically takes between 1 and 3 seconds. During the recovery period the database are frozen, and all database IO operation by CTDB clients are suspend.

To speed up the process of IP takeover and when clients attached to a failed node recovery as fast as possible. CTDB will automatically generate gratutions ARP packets to inform all nodes of the changed MAC address for that IP. CTDB will also send ‘tickle ack’ packets to all attached clients to trigger that clients to immediatlly recognized that the TCP connection needs to be re-established and to shortcut any TCP restransmission time outs that may be active in the clients.

CTDB current Architecture:
1. Multi-process server:
Multiple smbd daemons, one per client
Each daemon attached to a number of database
Database store all shared meta_data
2. Clustering this should be easy:
Why not just use a cluster database
Each smbd talkes to cluster database instead of local database
Obvious solution can be wrong.

CTDB is similarin conceps to Berkeley DB.

分类: 科技 标签:

Mandriva 2007: KMPlayer play rmvb

2007年8月4日 没有评论

I installed Mandriva 2K7 in my home PC. Fix the problem using KMPlay to play rmvb media. KMplayer can support the following types: GStream, xine and MPlayer. First, xine and Mplayer are able to play Mpeg format. When I try to open a rmvb file, Mplayer has only the sound without pictures, and it seems that xine does not support realplayer media.

As google suggestion, I set plf as Mandriva update source, and issue the below commands:

# urpmi xine-faad
# urpmi xine-flac
# urpmi real-codecs
# urpmi win32-codecs

Only flad can be installed,”xine-faad”,”real-codecs” and “win32-codecs” packagea are not found in the plf source. Hmm, I have to manually download the relevant packages from “rpm.pbone.net”. Note, “libstdc++5-3.3.6-3mdk.i586.rpm” is needed before install real-codes and win32-codes.

#wget ftp://mandrake.contactel.cz/plf/mandrake/2007.1/non-free/release/binary/i586/real-codecs-1.2-3plf.i586.rpm
#wget ftp://mirror.switch.ch/mirror/mandrake/official/2007.0/extra/i586/libstdc++5-3.3.6-3mdk.i586.rpm
#wget ftp://mandrake.contactel.cz/plf/mandrake/2007.0/non-free/release/binary/i586/win32-codecs-1.8-1plf2007.0.i586.rpm

# rpm -ivh libstdc++5-3.3.6-3mdk.i586.rpm
# rpm -ivh real-codecs-1.2-3plf.i586.rpm
# rpm -ivh win32-codecs-1.8-1plf2007.0.i586.rpm

OK, the KMplayer can play rmvb now.However, Mplayer trouble still exists.

分类: 科技 标签:

Alexandre Pato To Milan!

2007年8月3日 没有评论

From www.acmilan.com 8/2/2007
MILANO – The great talent Alexandre Pato will train with Milan and will be able to play the friendly matches starting from the 3rd of September 2007. From teh 3rd of January 2008 onwards he will also be able to play in the official games.

分类: 科技 标签:

Today of last year

2007年7月31日 没有评论

I went to work at Plasmon,Zhuhai in today of last year.
This 8 months experience is very senseful for myself development.

分类: 科技 标签:

Monthly Summary

2007年7月30日 没有评论

Study on CentOS 4.5 new features (Cluster Suite and Global File System) from the beginning of July, and finnally submit a detail Feasibility Study report at July 20th, the today before my birthday. This researching document indicating how to configure failover NFS(both active/passive and active/active) and GFS performance tunning, can greatly help our team in the next generation software. However, Samba failover across cluster has not been fixed.

Last week, I leaded three Engineers(Lin Peng, Hou Xianghua, Pang Rangsheng) to prepare the machines for UT customer. I learned a lot when working with this new group, and the most important thing is I must let every member in my team know his responsibilty. I act as directer, who stand in center to help the team accomplish the works. Second, make clear conclusion, continute or cancel the test, always focus on the target that these machines need be send to customer at Friday. Always encourage the team, calmly analyze the meeting problems and try to resolve it bravely. Respect everyone, and have good communication. In effection, clearly mind, strong decision and bravery are three key points.

In the following spare time, I think I should enhance the program ability and know deeply about computer networking. I plan to review C program at home, and if I have free time in office, I’d like to the book named “Computer Networking”. This study scheme is arranged to be accomplished in August.

Phillip, you have been 28 years old. Keep studing, never give up.

分类: 科技 标签:

Install Java Plug-In on Mozilla Firefox

2007年7月10日 没有评论

The BS3000/3000e WebGUI requires Java support, while the default Mozilla firefox on my Mandriva2K7 does not implement this plug-in. I fix this issue with the following steps.

1. Download the Java(TM) 2 RE(j2re-1.4.2-03-linux-i586.bin)
# wget ftp://ftp.informatik.hu-berlin.de/pub/Java/Linux/JDK-1.4.2/i386/03/j2re-1.4.2-03-linux-i586.bin

2. Change to the directory “/usr/local”
# cp j2re-1.4.2-03-linux-i586.bin /usr/local
# cd /usr/local
# chmod 777 j2re-1.4.2-03-linux-i586.bin

3. Extract the contents of the Java 2 SDK by running the shell script
# ./j2re-1.4.2-03-linux-i586.bin

4. Add j2re1.4.2/bin to PATH,
# export PATH=/usr/local/j2re1.4.2/bin:$PATH

5. Implement the Java Plug-In to Firefox:
#ln -s /usr/local/j2re1.4.2/plugin/i386/mozilla/libjavaplugin_oji.so /usr/lib/mozilla-firefox-1.5.0.7/plugins/

Note: It has to be a symbolic link, copying libjavaplugin_oji.so will NOT work. OK, the firefox is able to support Java GUI now.

分类: 科技 标签:

LVM2

2007年7月7日 没有评论

Logical Volume provide the following advantages over using physical storage directly:
1. Flexible capacity: file system can extend across multiple disks, since you can aggregate disks and partitions into a single logical volume.
2. Resizable storage pools: Extend/Reduce logical volumes
3. Online data relocation
4. Convenient device naming
5. Disk stripping, stripes data across two or more disks, this can dramatically increase throughout.
6. Mirror volume: logical volumes provide a convenient way to configure a mirror for your data.
7. Volumes snapshots: take device snapshots for consistent backups or to test the effect of changes without affecting the real data.

For the RHEL4 release, the original LVM1 becomes to LVM2. LUM is backward compatible with LVM1, with the expection of snapshot and cluster support. Convert a volume group from LUM1 to LVM2 with vgconvert command.

The clustered logical volume manager(CLVM) is a set of clustering extension to LVM, these extensions allows a cluster of computers to manager shared storage using LVM. clmvd daemon runs in each cluster computer with the same view of the logical volumes.

CLVM allows a user to configure logical volumes on a shared storage by locking access to physical storage while a logical volume is being configured, CLVM uses the locking service provides by high available symmetric infrastructure.

LVM logical volumes:
1. linear volumes
2. stripped logical volumes
3. mirrored logical volumes
4. snapshot volumes

Initializing a block device as a physical volume places a label near the start of the device. By default, the LVM label is placed in the second 512-bytes sector. You can overwrite this default by placing the label on any of the first 4 sectors.
LVM label identifies the devices as LVM physical volume. It contains a random unique identifier(the uuid) for the physical volume. It also stores the size of the block device in bytes, and it records where the LVM metadata will be stored on the devices.

LVM metadata is small an stored as ASCII.

Currently LVM allows you to store 0, 1 or 2 identifical copies of its metadata on each physical volume, the default is 1 copy, once you configure the number of metadata copies on the physical volume, you can not change the number at a later time. The first copy is stored at the start of the device, shortly after the label. If there’s a second copy, it is placed at the end of the device. If you accidently overwrite the area at the beginning of your disk by writting to a different disk than you intend, a second copy of metadata at the end of the device will allow you to recovery the metadata.

In Linux kernel, sector are considered to be 512 bytes in size.

Stripping performance:
LVM can not tell that two PV are on the same physical disk, if you create a striped logical volumes when two PV are on the same physical disk, the stripes could be on different partitions on the same disk. This would result in a decrease in performance rather than an increase.

Stripped logical volumes:
The filesystem lays the data out across the underlying physical volumes, you can control the way the data is written to the physical volumes by creating a stripped logical volumes.For large sequential reads and writes, this can improve the efficiency of the data I/O.

Stripping enhances performance by writing data to a predetermined number of physical volumes in round-round fashion. With stripping, I/O can be done in pararrel. In some situations, this can result in near-linear performance gain of each addtional pv in the stripe.

If you have two-way strip that uses up an entire volume group, adding a single physical volume to the volume group will not enable you to extend the stripe. Instead, you must add at least two PVs to the vg.

分类: 科技 标签:

clustat and required packages

2007年6月28日 没有评论

To monitor the cluster and display status at specific time intervals from a shell prompt, invoke clustat with the “-i” time option, where time specifies the number of seconds between status snapshots. The following example causes the clustat utility to display cluster status every 10 seconds
# clustat -i 10

The cluster configuration Tools automatically retains backup copies of the three most recently used configuration files (beside the currently used configuration File). Retaining the backup copies is useful if the cluster does not function correctly because of miconfiguration and you need to return to a precious working configuration.

rgmanager: manager cluster services and resoures.
system-config-cluster: contain the cluster configuration tool.
ccsd: contains the cluster configuration service daemon
magma: contains an interface library for cluster lock management
magma-plugins: contains plugins for the magma library.
cman: manager cluster membership, messaging and notification
cman-kernel: contains required cman kernal modules.
dlm: contains distributed lock managerment
dlm-kernel: contains required DLM kernel module
fence: The cluster I/O fencing system that allows cluster nodes to connect to a variety of network power switches fibre channel switches and integrited power managerment interfaces.
gulm: GuLM lock management tools/lib
iddev: contain libraries used to identify the filesytem(or volume manager) in which device is formatted.

GFS: The RedHat GFS module
GFS-kernel: GFS kernel module
gnbd: The GFS network block device module
gnbd-kernel: Kernel module for the GFS network block device
LVM2-Cluster: Cluster extensions for the logical volume manage.
gndb-kernelheader: gnbd kernel header files.

分类: 科技 标签:

Start/Stop Cluster

2007年6月28日 没有评论

Starting the cluster software in the below order:
# service ccsd start
# service cman start
# service fenced start (DLM cluster only)
# service clvmd start
# service gfs start
# service rgmanager start

Stop the cluster software in the below order:
# service rgmanager stop
# service gfs stop
# service clvmd stop
# service fenced stop
# service cman stop
# service ccsd stop

分类: 科技 标签: